mongodb / bson-rust

Encoding and decoding support for BSON in Rust
MIT License
400 stars 132 forks source link

Better Details for BSON Deserialization Errors #435

Open clarkmcc opened 11 months ago

clarkmcc commented 11 months ago

When I get a BSON deserialization error, it looks something like this

invalid type: unit value, expected a sequence

Is it possible to have the error contain more helpful information, like the path or something like that? I've been stomping out little deserialization issues for the last several months, and it's tricky to figure out exactly what set it off.

abr-egn commented 11 months ago

We recognize that the current error messages aren't great; unfortunately, the way serde is set up makes it tricky to include path or other source location. This is definitely on our roadmap, though - you can follow https://jira.mongodb.org/browse/RUST-1246 for updates.

clarkmcc commented 11 months ago

Thanks! Is it possible for me to somehow utilize dtolnay/path-to-error or would this need to be incorporated in this crate?

jaredtmartin commented 11 months ago

I'm in the same situation. I like your idea @clarkmcc of using dtolnay/path-to-error. Have you figured out how to implement it? If not have you found any other solution/workaround?

bastibense commented 11 months ago

Yes, please. The current errors are not very helpful at all and I had to trial-and-error myself through this. Feels bad, man.

clarkmcc commented 11 months ago

@jaredtmartin unfortunately I don't have a solution for this but yes, it's a real pain to deal with.