Improve error messages on operator[] or as<> (#656)

Invalid access via operator[] or as<> will now print the offending key, if possible.

For example:

a:
  x: 1
  y: 2

node["a"]["z"].as<int>()

will say that the key "z" was invalid.
This commit is contained in:
bedapisl
2019-04-17 15:44:09 +02:00
committed by Jesse Beder
parent bd7f8c60c8
commit 0122697561
7 changed files with 186 additions and 42 deletions

View File

@@ -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();
throw BadSubscript(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();
throw BadSubscript(key);
}
for (node_map::const_iterator it = m_map.begin(); it != m_map.end(); ++it) {