Skip to main content

ErrorReport

Struct ErrorReport 

Source
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

Source

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.

Source

pub fn from_dyn_error(error: Box<dyn Error + Send + Sync + 'static>) -> Self

Create an ErrorReport from a boxed dynamic error.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn get_last_error_title(&self) -> String

Get the display string of the last error in the chain.

Source

pub fn get_unique_id(&self) -> String

Get the unique identifier for this error report.

Source

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.

Trait Implementations§

Source§

impl Debug for ErrorReport

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ErrorReport

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl ErrorFmt for ErrorReport

Source§

fn create_format_obj( &self, settings: ErrorFmtSettings, ) -> ResultER<ErrorFormatObj>

Convert this value into a structured format object.
Source§

fn stringify(&self, settings: ErrorFmtSettings) -> ResultER<String>

Convert to string by first creating a format object, then stringifying it.
Source§

fn stringify_obj( format_obj: ErrorFormatObj, settings: ErrorFmtSettings, ) -> ResultER<String>

Stringify an existing format object directly.
Source§

impl<E: Error + Send + Sync + 'static> From<E> for ErrorReport

Source§

fn from(error: E) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more