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.
Most helpful comment
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 :)