Skip to content

Exception for missing value is non-descriptive #423

@joseph-ireland

Description

@joseph-ireland

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions