Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add key name when throwing type error #1189

Closed
icaroalvarez opened this issue Aug 6, 2018 · 1 comment
Closed

Add key name when throwing type error #1189

icaroalvarez opened this issue Aug 6, 2018 · 1 comment
Labels
solution: duplicate the issue is a duplicate; refer to the linked issue instead

Comments

@icaroalvarez
Copy link

Congrats for the project. Really cool. I don't know if this is too much concrete and only adds value for my use case but I think it could be usefull to add the name of the key that fails when throwing a type error exception. This way I would fast know where I made a mistake.

For example, it would be helpfull while using json for program parameter configuration:

nlohmann::json config_json =
            {
                    {"param_one", 1},
                    {"param_two", 2}
            };

    try {
        bool param_one = config_json.at("param_one");
        int param_two = config_json.at("param_two");
    }catch(const std::exception& e)
    {
        FAIL(e.what());
    }

The exception message is: [json.exception.type_error.302] type must be boolean, but is number

It could be nice if the message ended with: (in key "param_one").

Just a thought. Cheers!

@nlohmann
Copy link
Owner

nlohmann commented Aug 6, 2018

Duplicate: #932

@nlohmann nlohmann closed this as completed Aug 6, 2018
@nlohmann nlohmann added the solution: duplicate the issue is a duplicate; refer to the linked issue instead label Aug 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: duplicate the issue is a duplicate; refer to the linked issue instead
Projects
None yet
Development

No branches or pull requests

2 participants