pub struct ErrorReport {
pub frames: Vec<ErrorFrame>,
/* private fields */
}Expand description
The core error type that collects a chain of ErrorFrames.
An ErrorReport holds an ordered list of error frames, from the most specific
(the original trigger) to the most general (the top-level context). Each frame
captures the error, source location, timestamp, backtrace, tracing span, and
optional attachments.
§Creating an ErrorReport
use charon_error::{ErrorReport, StringError};
let report = ErrorReport::from_error(StringError::new("disk full"));§Chaining errors
use charon_error::{ErrorReport, StringError};
let report = ErrorReport::from_error(StringError::new("io error"))
.push_error(StringError::new("failed to save file"));§Using with Result
Use ResultER<T> and the ResultExt
trait for ergonomic error handling:
use charon_error::prelude::*;
fn read_file() -> ResultER<String> {
std::fs::read_to_string("data.txt")
.change_context(StringError::new("failed to read data file"))
}Fields§
§frames: Vec<ErrorFrame>All error frames listed from most specific error (trigger) to most general error (effected).
Implementations§
Source§impl ErrorReport
impl ErrorReport
Sourcepub fn from_error<E: Error + Send + Sync + 'static>(error: E) -> Self
pub fn from_error<E: Error + Send + Sync + 'static>(error: E) -> Self
Create an ErrorReport from any error type.
This is the primary constructor. The error is wrapped in an ErrorFrame
that captures the source location, backtrace, and current tracing span.
Sourcepub fn from_dyn_error(error: Box<dyn Error + Send + Sync + 'static>) -> Self
pub fn from_dyn_error(error: Box<dyn Error + Send + Sync + 'static>) -> Self
Create an ErrorReport from a boxed dynamic error.
Sourcepub fn from_anyhow_error_ref(error: &Error) -> Self
pub fn from_anyhow_error_ref(error: &Error) -> Self
Create an ErrorReport from an anyhow::Error reference.
Walks the error chain and creates a frame for each cause.
Sourcepub fn push_error<R: Error + Send + Sync + 'static>(self, new_error: R) -> Self
pub fn push_error<R: Error + Send + Sync + 'static>(self, new_error: R) -> Self
Add a new error to the chain, providing higher-level context.
Returns self for chaining.
Sourcepub fn attach<S: Into<String>>(
self,
key_name: S,
attachment: ErrorSensitivityLabel<ErrorAttachment>,
) -> Self
pub fn attach<S: Into<String>>( self, key_name: S, attachment: ErrorSensitivityLabel<ErrorAttachment>, ) -> Self
Attach labeled data to the most recent error frame.
Attachments are key-value pairs wrapped in an ErrorSensitivityLabel
to control visibility in reports.
§Panics
Panics if the report has no frames.
Sourcepub fn get_last_error(&self) -> &Box<dyn Error + Send + Sync + 'static>
pub fn get_last_error(&self) -> &Box<dyn Error + Send + Sync + 'static>
Get a reference to the last (most general) error in the chain.
§Panics
Panics if the report has no frames.
Sourcepub fn get_last_error_title(&self) -> String
pub fn get_last_error_title(&self) -> String
Get the display string of the last error in the chain.
Sourcepub fn get_unique_id(&self) -> String
pub fn get_unique_id(&self) -> String
Get the unique identifier for this error report.
Sourcepub fn attach_public_string<S: Into<String>, A: Display>(
self,
key_name: S,
attachment: A,
) -> Self
pub fn attach_public_string<S: Into<String>, A: Display>( self, key_name: S, attachment: A, ) -> Self
Shorthand to attach a public string to the most recent frame.