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 refusedMany 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 inputNested 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§
Trait Implementations§
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> 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