Using the example given in the tutorial:
YAML::Node config = YAML::LoadFile("config.yaml");
if (config["lastLogin"]) {
std::cout << "Last logged in: " << config["lastLogin"].as<DateTime>() << "\n";
}
const std::string username = config["username"].as<std::string>();
const std::string password = config["password"].as<std::string>();
login(username, password);
config["lastLogin"] = getCurrentDateTime();
std::ofstream fout("config.yaml");
fout << config;
and the following YAML file:
usernaem: "user" # typo in key
password: "password
generates the exception
terminate called after throwing an instance of 'YAML::InvalidNode'
what(): invalid node; this may result from using a map iterator as a sequence iterator, or vice-versa
Given any half-complex setup, this is impossible to debug without pulling up GDB, so all code is filled with manual error-checking for every field.
My suggestion given the current API would be to just add an stl-style YAML::Node at(T key), which throws on failure, allowing the error to contain the key (at least in the case of string/int), and the Mark() for the parent node.
Using the example given in the tutorial:
and the following YAML file:
generates the exception
Given any half-complex setup, this is impossible to debug without pulling up GDB, so all code is filled with manual error-checking for every field.
My suggestion given the current API would be to just add an stl-style
YAML::Node at(T key), which throws on failure, allowing the error to contain the key (at least in the case of string/int), and the Mark() for the parent node.