Skip to main content

ErrorReport

Struct ErrorReport 

Source
pub struct ErrorReport<'a>(pub &'a (dyn Error + 'static));
Expand description

A formatted error report.

ErrorReport wraps a reference to a 'static error and formats it with its full causal chain. It is created via ErrorExt::report.

The report automatically detects Many and renders them as a tree structure. Linear error chains are rendered with the same tree characters for visual consistency.

§Output Format

Linear chain:

Failed to start service, at src/main.rs:42:10
|-- Failed to initialize database, at src/db.rs:15:5
`-- connection refused

Many causes (tree):

Batch operation failed, at src/main.rs:20:5 (3 causes)
|-- Task A failed, at src/worker.rs:8:9
|   `-- I/O error: file not found
|-- Task B failed, at src/worker.rs:12:9
|   `-- network timeout
`-- Task C failed, at src/worker.rs:16:9
    `-- invalid input

Nested Many:

Distributed operation failed, at src/cluster.rs:50:5 (2 causes)
|-- Node A batch failed, at src/node.rs:25:10 (2 causes)
|   |-- Task 1 failed
|   `-- Task 2 failed
`-- Node B batch failed, at src/node.rs:30:10 (1 cause)
    `-- Task 3 failed

§Example

use scoped_error::{Error, expect_error, ErrorExt};

let err: Error = expect_error("Database connection failed", || {
    std::fs::read_to_string("nonexistent")?;
    Ok(())
}).unwrap_err();

println!("{}", err.report());
// Output:
// Database connection failed, at src/main.rs:3:5
// `-- No such file or directory (os error 2)

Tuple Fields§

§0: &'a (dyn Error + 'static)

Implementations§

Source§

impl<'a> ErrorReport<'a>

Source

pub fn new(error: &'a (dyn Error + 'static)) -> Self

Create a new error report from an error reference.

The error must be 'static to allow downcasting for Many detection.

Trait Implementations§

Source§

impl Display for ErrorReport<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ErrorReport<'a>

§

impl<'a> !RefUnwindSafe for ErrorReport<'a>

§

impl<'a> !Send for ErrorReport<'a>

§

impl<'a> !Sync for ErrorReport<'a>

§

impl<'a> Unpin for ErrorReport<'a>

§

impl<'a> UnsafeUnpin for ErrorReport<'a>

§

impl<'a> !UnwindSafe for ErrorReport<'a>

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<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.