Most examples in the SNAFU guide show the following pattern:
#[derive(Debug, Snafu)]
#[non_exhaustive]
pub enum Error {
#[snafu(display("Could not read data set token: {}", source))]
#[non_exhaustive]
ReadToken {
#[snafu(backtrace)]
source: dicom_parser::dataset::read::Error,
},
}Notice how the source field is chained to the tail of
the type's display implementation.
This makes it so that a single line print is enough to present
all information about the error (minus the backtrace).
eprintln!("[ERROR] {}", e);one possible output:
[ERROR] Could not read data set token: Could not read item value: Undefined value length of element tagged (5533,5533) at position 3548
However, this will not integrate well with other error reporting facilities,
such as eyre, which are already prepared
to traverse the chain of error causes and show them individually.
If we were to turn our error into an eyre::Report and print that:
eprintln!("[ERROR] {:?}", eyre::Report::from(e));We get this twisted mess of repetition:
[ERROR] Could not read data set token: Could not read item value: Undefined value length of element tagged (5533,5533) at position 3548
Caused by:
0: Could not read item value: Undefined value length of element tagged (5533,5533) at position 3548
1: Undefined value length of element tagged (5533,5533) at position 3548