json icon indicating copy to clipboard operation
json copied to clipboard

Path to errors

Open dtolnay opened this issue 8 years ago • 8 comments

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.

dtolnay avatar Dec 08 '16 19:12 dtolnay

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.

dtolnay avatar Feb 09 '17 00:02 dtolnay

I implemented this for serde_yaml in https://github.com/dtolnay/serde-yaml/pull/43. Just need to port it over to JSON.

dtolnay avatar Feb 11 '17 01:02 dtolnay

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.

allistercsmith avatar Dec 29 '18 07:12 allistercsmith

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.

dtolnay avatar Jan 07 '19 00:01 dtolnay

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 :)

matklad avatar Jan 08 '20 13:01 matklad

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.

asafigan avatar Aug 22 '20 04:08 asafigan

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 ).

ansrivas avatar May 17 '22 13:05 ansrivas

So any plans to make this standard and to update the default Display impl to include the full path when missing fields?

cole-abbeduto-particle avatar Dec 19 '23 22:12 cole-abbeduto-particle