pub struct ErrorChain { /* private fields */ }Available on crate feature
alloc only.Expand description
A diagnostic pairs a GraphError with an optional causal chain.
Both the outer error and every inner cause carry their own WDP code, forming a chain that provides context (what failed) at each level:
[E.ArenaLayout.Builder.026] IR builder allocation failed
caused by: [E.ArenaLayout.Alloc.026] arena out of memory§Construction
use ascii_dag::errors::{GraphError, ErrorChain};
// Leaf diagnostic (no cause)
let d = ErrorChain::from(GraphError::ArenaOom);
assert_eq!(d.code(), "E.ArenaLayout.Alloc.026");
assert!(d.cause().is_none());
// Chained diagnostic
let d = ErrorChain::from(GraphError::BuilderFailed)
.caused_by(GraphError::ArenaOom);
assert_eq!(d.code(), "E.ArenaLayout.Builder.026");
assert_eq!(d.cause().unwrap().code(), "E.ArenaLayout.Alloc.026");§Display
Display renders the full chain, indenting each cause level:
use ascii_dag::errors::{GraphError, ErrorChain};
let d = ErrorChain::from(GraphError::BuilderFailed)
.caused_by(GraphError::ArenaOom);
let msg = d.to_string();
assert!(msg.contains("caused by:"));Implementations§
Source§impl ErrorChain
impl ErrorChain
Sourcepub fn new(error: GraphError) -> Self
pub fn new(error: GraphError) -> Self
Create a leaf diagnostic (no cause).
Sourcepub fn caused_by(self, cause: GraphError) -> Self
pub fn caused_by(self, cause: GraphError) -> Self
Attach a cause to this diagnostic (builder pattern).
The cause is wrapped in its own ErrorChain with no further inner
cause. For deeper chains, use caused_by_chain.
Sourcepub fn caused_by_chain(self, cause: ErrorChain) -> Self
pub fn caused_by_chain(self, cause: ErrorChain) -> Self
Attach an existing ErrorChain as the cause.
Sourcepub fn error(&self) -> &GraphError
pub fn error(&self) -> &GraphError
The GraphError at this level of the chain.
Sourcepub fn cause(&self) -> Option<&ErrorChain>
pub fn cause(&self) -> Option<&ErrorChain>
The inner cause, if any.
Sourcepub fn chain(&self) -> DiagnosticChain<'_> ⓘ
pub fn chain(&self) -> DiagnosticChain<'_> ⓘ
Iterate over the full chain: self, then cause, then cause’s cause, etc.
Trait Implementations§
Source§impl Clone for ErrorChain
impl Clone for ErrorChain
Source§fn clone(&self) -> ErrorChain
fn clone(&self) -> ErrorChain
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ErrorChain
impl Debug for ErrorChain
Source§impl Display for ErrorChain
impl Display for ErrorChain
impl Eq for ErrorChain
Source§impl Error for ErrorChain
Available on crate feature std only.
impl Error for ErrorChain
Available on crate feature
std only.Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl From<GraphError> for ErrorChain
impl From<GraphError> for ErrorChain
Source§fn from(error: GraphError) -> Self
fn from(error: GraphError) -> Self
Converts to this type from the input type.
Source§impl PartialEq for ErrorChain
impl PartialEq for ErrorChain
Source§impl ProjectedFailure for ErrorChain
impl ProjectedFailure for ErrorChain
impl StructuralPartialEq for ErrorChain
Auto Trait Implementations§
impl Freeze for ErrorChain
impl RefUnwindSafe for ErrorChain
impl Send for ErrorChain
impl Sync for ErrorChain
impl Unpin for ErrorChain
impl UnsafeUnpin for ErrorChain
impl UnwindSafe for ErrorChain
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more