From cf93f4c57ba67fcf6c3f4f0d6ab9a2831dfbd47f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Matar=C3=A9?= Date: Tue, 7 Apr 2020 18:33:16 +0200 Subject: [PATCH] Pass a mark to BadSubscript exception (#843) It's clearly related to an existing node, so it can have a mark and give an error location. --- include/yaml-cpp/exceptions.h | 4 ++-- include/yaml-cpp/node/detail/impl.h | 4 ++-- src/node_data.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/yaml-cpp/exceptions.h b/include/yaml-cpp/exceptions.h index 16b1efa..055d274 100644 --- a/include/yaml-cpp/exceptions.h +++ b/include/yaml-cpp/exceptions.h @@ -248,8 +248,8 @@ class YAML_CPP_API BadDereference : public RepresentationException { class YAML_CPP_API BadSubscript : public RepresentationException { public: template - BadSubscript(const Key& key) - : RepresentationException(Mark::null_mark(), + BadSubscript(const Mark& mark_, const Key& key) + : RepresentationException(mark_, ErrorMsg::BAD_SUBSCRIPT_WITH_KEY(key)) {} BadSubscript(const BadSubscript&) = default; ~BadSubscript() YAML_CPP_NOEXCEPT override; diff --git a/include/yaml-cpp/node/detail/impl.h b/include/yaml-cpp/node/detail/impl.h index a5cbc0a..bbefd59 100644 --- a/include/yaml-cpp/node/detail/impl.h +++ b/include/yaml-cpp/node/detail/impl.h @@ -122,7 +122,7 @@ inline node* node_data::get(const Key& key, return pNode; return nullptr; case NodeType::Scalar: - throw BadSubscript(key); + throw BadSubscript(m_mark, key); } for (node_map::const_iterator it = m_map.begin(); it != m_map.end(); ++it) { @@ -150,7 +150,7 @@ inline node& node_data::get(const Key& key, shared_memory_holder pMemory) { convert_to_map(pMemory); break; case NodeType::Scalar: - throw BadSubscript(key); + throw BadSubscript(m_mark, key); } for (node_map::const_iterator it = m_map.begin(); it != m_map.end(); ++it) { diff --git a/src/node_data.cpp b/src/node_data.cpp index f0c776d..e91d12a 100644 --- a/src/node_data.cpp +++ b/src/node_data.cpp @@ -196,7 +196,7 @@ void node_data::insert(node& key, node& value, shared_memory_holder pMemory) { convert_to_map(pMemory); break; case NodeType::Scalar: - throw BadSubscript(key); + throw BadSubscript(m_mark, key); } insert_map_pair(key, value); @@ -226,7 +226,7 @@ node& node_data::get(node& key, shared_memory_holder pMemory) { convert_to_map(pMemory); break; case NodeType::Scalar: - throw BadSubscript(key); + throw BadSubscript(m_mark, key); } for (node_map::const_iterator it = m_map.begin(); it != m_map.end(); ++it) {