shepmaster / snafu

Easily assign underlying errors into domain-specific errors while adding context
https://docs.rs/snafu/
Apache License 2.0
1.4k stars 60 forks source link

alternate `Display` to include the source chain #390

Open BugenZhao opened 1 year ago

BugenZhao commented 1 year ago

Hi, and thanks for your work on this great library!

I'm considering if it's possible to support displaying the source chain with alternate Display (i.e. {:#}), which seems to be a convention for error reporting utilized in many other error handling libraries, including anyhow and error-stack.

shepmaster commented 1 year ago

Does report or Report not work for you?

BugenZhao commented 1 year ago

Yeah, it seems Report has a similar idea. However, I have several concerns...

shepmaster commented 1 year ago

I'm not sure if developers always remember

How would this be different from remembering to use the alternate display flag?

which I guess should be a good practice

The current best practice is to do exactly one of:

Report always includes the backtrace if provided

Right now, it only happens on nightly Rust if you've enabled the unstable-provider-api feature flag, but at some point in the future it might happen by default. We might also add some small configuration knobs.

shepmaster commented 1 year ago

utilized in many other error handling libraries

I believe the big difference is that these other libraries (and I'm not an expert on them) don't actually give you control over the implementation of Display in the first place, while SNAFU does. For example, could you share your desired syntax to specify the regular and alternate Display implementations for a SNAFU-enhanced error?

We have had some discussions about some kind of #[snafu(display(false))] style option that would disable the creation of the Display implementation, letting the user define it completely by hand. That would allow uncommon / highly special cases without completely jettisoning SNAFU.