json
json copied to clipboard
Path to errors
Newer versions of Jackson are really helpful about giving you the full path to the thing that errored out. See if this is something we can do with minimal performance impact or behind a flag.
This repo includes a relatively cheap way to track the path within a Deserializer:
https://github.com/dtolnay/serde-ignored
Let's factor the path-tracking part out and use it for errors in serde_json.
I implemented this for serde_yaml in https://github.com/dtolnay/serde-yaml/pull/43. Just need to port it over to JSON.
Hey @dtolnay 👋 Have you managed to make any headway on this change? I see you mentioned in https://github.com/serde-rs/serde/pull/710 that you had a design in mind, but that was quite a while ago - can't see any other updates since then.
I'm currently building an API in Rust, which will be publicly consumable once launched. Having clear error messages (i.e., path + error) is quite a fundamental piece of this.
I'm quite new to the Rust scene, but I'd be happy to try get my hands dirty if there's nothing in progress here? I was also looking at https://github.com/dtolnay/serde-ignored for inspiration.
Here is the library: https://github.com/dtolnay/path-to-error. You can use it to wrap any Deserializer and find out where an error occurs.
This is a really useful library, just helped me to instantly pin-point a bug right now, thanks!
Would be lovely to have this built-in into serde-json
, both to improve visibility, and to reduce the amount of patching required if deserialziation happens in the dependency :)
I don't know if this should be a different issue but I would love a fail slow feature flag or a separate function. It would continue parsing after the first error and find all errors. That way I could have information about all missing fields or all fields with incorrect types. I am new to Rust but I would love to contribute because I really want this.
This is a really useful library, just helped me to instantly pin-point a bug right now, thanks!
Would be lovely to have this built-in into
serde-json
, both to improve visibility, and to reduce the amount of patching required if deserialziation happens in the dependency :)
Thank you for this library :)
This just happened in one of the projects - if I am the client invoking other APIs, I quickly introduced path-to-error
and now I can very easily debug errors.
But I am using other projects which simply use serde-json
for e.g. actix-web uses it to deserialize incoming json requests. Would be really great if this gets included in the base lib ( behind a feature flag if needed ).
So any plans to make this standard and to update the default Display impl to include the full path when missing fields?