dtolnay/anyhow

anyhow Debug trail impl uses the Display for all the errors in the chain and not Debug

DanielBauman88 opened this issue · 2 comments

I guess this is intentional, but I'm curious about the reasoning, and if this is the right thing then perhaps anyhow should supply a different method for printing the debug of the cause.

EG: I create an anyhow error with anyhow!(error) where error is an aws sdk error message. The display message doesn't give me a lot of useful information for the sdk error.
I'd like to log the debug for that error. But when I debug log the anyhow! error this isn't what I get.

Should the debug impl here: dtolnay/anyhow@master/src/fmt.rs#L26 not use the {:?} debug formatting?

Here's a playground example illustrating the issue - play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=5aefcdee5fed06749c401042c9ec081b

The usability of anyhow to track errors through a codebase and finally log them with a call stack is fantastic! I love it. But not wanting to lose the full information of the cause error breaks the ergonomics because I can't construct directly from the error with anyhow!

This is intentional. In your playground link, you've written a low-quality Display impl. If the String inside that error is relevant to display to a user when displaying that error, then you need to make your Display impl display it.

I see! I played around with this some more and noticed the same with AWS SDK Errors. Thanks for the explanation!