serde-rs / json

Strongly typed JSON library for Rust
Apache License 2.0
4.91k stars 560 forks source link

`ser::Error` completely hides inner `io::Error` #1169

Open tingerrr opened 3 months ago

tingerrr commented 3 months ago

I am using anyhow in a CLI project, which filters out broken pipe errors at the top level main. When writing JSON directly to a closed stdout the returned root_cause is the JSON ser::Error itself, not the underlying io::Error.

It turns out, the implementation of Error::source for ser::Error does not return the actual source of the JSON Error, but the transitive source of its inner io::Error. This was introduced in #992.

I think it would probably be better to return the correct Error::source and simply format the io case for ser::Error as an io error occured to avoid the dupe message.