1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
//! Contains methods useful for error handling

/// Writes a chain of error causes to a formatter
pub fn error_chain_fmt(
    e: &impl std::error::Error,
    f: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
    writeln!(f, "{}\n", e)?;
    let mut current = e.source();
    while let Some(cause) = current {
        writeln!(f, "Caused by:\n\t{}", cause)?;
        current = cause.source();
    }
    Ok(())
}