Skip to content

Commit

Permalink
missing keys should throw InvalidNode, not BadConversion
Browse files Browse the repository at this point in the history
Fixes GH jbeder#1274
  • Loading branch information
Reini Urban committed Nov 1, 2024
1 parent c2bec4c commit 477966f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/yaml-cpp/node/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ struct as_if<T, void> {
const Node& node;

T operator()() const {
if (!node.m_pNode)
throw TypedBadConversion<T>(node.Mark());
if (!node.m_pNode) // no fallback
throw InvalidNode(node.m_invalidKey);

T t;
if (convert<T>::decode(node, t))
Expand Down
6 changes: 6 additions & 0 deletions test/integration/load_node_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ TEST(NodeSpecTest, InfiniteLoopNodes) {
EXPECT_THROW(LoadAll(R"(,)"), ParserException);
}

TEST(NodeTest, LoadMissingKey) {
Node node;
node["foo"] = "value";
EXPECT_THROW(node.["bar"], InvalidNode);
}

struct NewLineStringsTestCase {
std::string input;
std::string expected_content;
Expand Down

0 comments on commit 477966f

Please sign in to comment.