use std::error::Error;
use std::fmt::{Display, Formatter, Result as FResult};
use error_trace::ErrorTrace as _;
#[derive(Debug)]
struct SomeError {
msg: String,
}
impl Display for SomeError {
fn fmt(&self, f: &mut Formatter<'_>) -> FResult { write!(f, "{}", self.msg) }
}
impl Error for SomeError {}
#[derive(Debug)]
struct HigherError {
msg: String,
child: SomeError,
}
impl Display for HigherError {
fn fmt(&self, f: &mut Formatter<'_>) -> FResult { write!(f, "{}", self.msg) }
}
impl Error for HigherError {
fn source(&self) -> Option<&(dyn 'static + Error)> { Some(&self.child) }
}
fn main() {
let err = HigherError { msg: "Oh no, something went wrong!".into(), child: SomeError { msg: "A specific reason".into() } };
eprintln!("{}", err.trace_colored());
}