thiserror
thiserror copied to clipboard
Display cause chain when alternate format is used
As thiserror is complementary to anyhow, and anyhow supports {:#} format, would be nice if thiserror errors supported it too. This way in codebases that mix thiserror and anyhow errors, it would be possible to use {:#} everywhere and get cause chains printed for all errors.
I also need this. Do you want me to make a PR?
On the other hand, if you wrap the error into anyhow again, you can have it printed nicely without thiserror's support. Just need to make sure that when doing .downcast_ref() the original error is printed instead of downcasted.
I like the approach proposed in https://github.com/dtolnay/anyhow/issues/111 more than this one, actually. Just change anyhow and thiserror to print causes by default and make {} the same as {:#}.
It's hard to say. I like to be able to do both. I.e. when printing vertically or when printing error messages together with backtraces.
I don't mind if {} meant with causes but {:#} meant without (i.e. opposite than what we have now). But since a lot of applications are probably relying on current behavior it's weird to change now.
Other reasons to keep current behavior:
{:#}is similar to{:#?}by meaning: longer more detailed output- We write
#[error("some text with {}", values)], it's intuitive thatDisplayshows onlysome text with values. If it adds: some longer thing: and another oneto the output and you need{:#}"to do what I meant" it looks weird.
I see #233 was closed in favor of using anyhow as the error reporter and so gaining access to {:#} but this issue is still open. I agree about the rationale of keeping thiserror clean of "reporting", but at the same time, this is a caveat we need to remember or fix after when pieces of code migrate away from using anyhow to matchable errors.
{:#} cannot be bolted on by users of the crate; a formatting fn like we have report_compact_sources, but that is easy to forget. Would a PR introducing this alternate if the impl would be calling back into thiserror on a #[doc(hidden)] function for the reporting be welcome?