diff --git a/src/future/race_ok/array/error.rs b/src/future/race_ok/array/error.rs index 841e4ee..23e3d6e 100644 --- a/src/future/race_ok/array/error.rs +++ b/src/future/race_ok/array/error.rs @@ -1,5 +1,6 @@ use core::fmt; use core::ops::{Deref, DerefMut}; +use std::error::Error; /// A collection of errors. #[repr(transparent)] @@ -13,19 +14,26 @@ impl AggregateError { } } -impl fmt::Debug for AggregateError { +impl fmt::Debug for AggregateError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut list = f.debug_list(); - for err in self.inner.as_ref() { - list.entry(err); + writeln!(f, "{self}:")?; + + for (i, err) in self.inner.iter().enumerate() { + writeln!(f, "- Error {}: {err}", i + 1)?; + let mut source = err.source(); + while let Some(err) = source { + writeln!(f, " ↳ Caused by: {err}")?; + source = err.source(); + } } - list.finish() + + Ok(()) } } -impl fmt::Display for AggregateError { +impl fmt::Display for AggregateError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Debug::fmt(self, f) + write!(f, "{} errors occured", self.inner.len()) } } @@ -43,4 +51,4 @@ impl DerefMut for AggregateError { } } -impl std::error::Error for AggregateError {} +impl std::error::Error for AggregateError {}