snafu icon indicating copy to clipboard operation
snafu copied to clipboard

feat: show sources on alternate display

Open Frando opened this issue 2 months ago • 1 comments

Implements a fix to #390:

When printing an error that has the Snafu derive with the alternate display formatter ({err:#}), the list of sources is attached, similar to how anyhow does it.

This is similar to the Report, but without needing to take ownership of the error (which Report requireds) and without spreading the display over multiple lines.

It is especially useful when logging errors while also bubbling them up. We frequently want to log errors, and currently this will not print the source chain, rendering the log mostly irrelevant. With this change, you can do

tracing::warn!("{err:#}")

And get a log like

Get failed: IO failure: pipe is broken

(from the simple example - which I can remove of course if this PR is being considered for merging).

Frando avatar Oct 06 '25 09:10 Frando