How to get error message from glz::err_ctx? #1790
Replies: 6 comments 7 replies
|
Call the function If you have a recent version of Glaze then the specific missing key will be included in the formatted error. |
|
@stephenberry Thank you. I've got the newest one from Github, and it gives me "index 13: unknown_key". I was reading in json, does this mean an unknown key in the json or the struct it's deserialising into? Is it possible to give the name of the key? |
|
@Please-just-dont OK, I tried doing it with reflect_cpp, and I got:
I think I'll keep reflect-cpp around as it might come in handy. Thank you. |
|
@Please-just-dont Just letting you know the differences in case you wanted to know. In Glaze if you have a field in your struct that's not in the JSON it's just ignored. In reflect-cpp if it's in your struct but not in the json it gives as error UNLESS you wrap the field in an optional. It seems that in both Glaze and reflect-cpp if there's a field in the json and not in your struct that's an outright error. |
|
@stephenberry Hmm, so if you want to provide options you have to use read instead of read_json, right? And if you do there' no longer the overload that returns the struct in glz::expected but only the overload where you pass in the buffer, right? There's no difference between these methods? |
|
@stephenberry "If you'd like, we could add a version for read with options that also allocates the value" - no that's OK, I can just pass the buffer in. I'm keeping both Glaze and reflect-cpp wrapped up so I can use both of them. Just to let you know, to get the error you do:
and it returns an std::string with "unknown_key". Then there's another overload thats:
And if you pass an std::string to the const auto& buffer it returns:
So a bit more information, but the index 13 doesn't correspond to anything. Also, the string that I pass into the buffer as second argument is always empty, not sure what that's supposed to be for. Thank you for everything. |
Uh oh!
There was an error while loading. Please reload this page.
Hi, when I get an error, how am I supposed to a human readable error message? I can see through the debugger that the ec is 'unknown_key'. How can I get this as a string. Also, is that all the info that's provided? Just 'unknown_key', does it show the name of the actual key?
Thank you.
All reactions