pub struct ErrorCollector { /* private fields */ }Expand description
Thread-safe error collector that deduplicates errors by root cause.
Designed to replace the error_occurred: bool + generic-error-message pattern
used throughout the codebase. Stores the first error with its full anyhow::Error
chain intact, deduplicates subsequent errors by root cause string, and caps the
number of unique causes tracked.
Implementations§
Source§impl ErrorCollector
impl ErrorCollector
Sourcepub fn new(max_unique: usize) -> Self
pub fn new(max_unique: usize) -> Self
Creates a new collector that tracks up to max_unique distinct root causes.
Sourcepub fn push(&self, error: Error)
pub fn push(&self, error: Error)
Records an error. The first error’s full chain is preserved; subsequent errors are deduplicated by their root cause string.
Sourcepub fn has_errors(&self) -> bool
pub fn has_errors(&self) -> bool
Returns true if any errors have been recorded.
Sourcepub fn take_error(&self) -> Option<Error>
pub fn take_error(&self) -> Option<Error>
Returns the final error, or None if no errors occurred.
- If there is exactly one unique root cause, returns the original first error
with its full anyhow chain intact (so
{:#}works correctly downstream). - If there are multiple unique root causes, returns a new error listing all of them.
- If more errors were seen than tracked, appends a count of suppressed causes.
Can be called on a shared reference (e.g., through Arc). Takes the first error
out of the collector, so subsequent calls will return a synthesized error if any
errors were recorded.
Sourcepub fn into_error(self) -> Option<Error>
pub fn into_error(self) -> Option<Error>
Consumes the collector and returns the final error. Equivalent to Self::take_error
but takes ownership, guaranteeing no other references exist.
Trait Implementations§
Source§impl Debug for ErrorCollector
impl Debug for ErrorCollector
Auto Trait Implementations§
impl !Freeze for ErrorCollector
impl RefUnwindSafe for ErrorCollector
impl Send for ErrorCollector
impl Sync for ErrorCollector
impl Unpin for ErrorCollector
impl UnsafeUnpin for ErrorCollector
impl UnwindSafe for ErrorCollector
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request