From db6deedcd301754723065e0bbb1b75927c5b49c7 Mon Sep 17 00:00:00 2001 From: Snow Pettersen Date: Fri, 23 Jul 2021 15:52:21 -0400 Subject: [PATCH] Include name of anchor in invalid anchor error (#1015) --- include/yaml-cpp/exceptions.h | 2 +- src/singledocparser.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/yaml-cpp/exceptions.h b/include/yaml-cpp/exceptions.h index c3f4474..f6b2602 100644 --- a/include/yaml-cpp/exceptions.h +++ b/include/yaml-cpp/exceptions.h @@ -65,7 +65,7 @@ const char* const ZERO_INDENT_IN_BLOCK = const char* const CHAR_IN_BLOCK = "unexpected character in block scalar"; const char* const AMBIGUOUS_ANCHOR = "cannot assign the same alias to multiple nodes"; -const char* const UNKNOWN_ANCHOR = "the referenced anchor is not defined"; +const char* const UNKNOWN_ANCHOR = "the referenced anchor is not defined: "; const char* const INVALID_NODE = "invalid node; this may result from using a map iterator as a sequence " diff --git a/src/singledocparser.cpp b/src/singledocparser.cpp index 405ecad..22913d1 100644 --- a/src/singledocparser.cpp +++ b/src/singledocparser.cpp @@ -424,8 +424,11 @@ anchor_t SingleDocParser::RegisterAnchor(const std::string& name) { anchor_t SingleDocParser::LookupAnchor(const Mark& mark, const std::string& name) const { auto it = m_anchors.find(name); - if (it == m_anchors.end()) - throw ParserException(mark, ErrorMsg::UNKNOWN_ANCHOR); + if (it == m_anchors.end()) { + std::stringstream ss; + ss << ErrorMsg::UNKNOWN_ANCHOR << name; + throw ParserException(mark, ss.str()); + } return it->second; }