Skip to main content

Crate thistrace

Crate thistrace 

Source
Expand description

thistrace adds callsite provenance (file/line/column) to thiserror enums without requiring map_err(...) at each callsite.

It works by generating #[track_caller] From<T> impls for #[from] conversions, so ? captures the location where the conversion happened.

§Quickstart

use thistrace::prelude::*;

#[traceable]
#[derive(Debug, thiserror::Error)]
enum AppError {
    #[error("io")]
    Io(#[from] Origin<std::io::Error>),
}

fn leaf() -> Result<(), Origin<std::io::Error>> {
    Err(origin(std::io::Error::new(std::io::ErrorKind::Other, "boom")))
}

fn top() -> Result<(), AppError> {
    leaf()?; // adds a conversion/bubble frame
    Ok(())
}

let err = top().unwrap_err();
let _ = format!("{}", OneLineTrace::new(&err));
assert!(!trace_frames(&err).is_empty());

Modules§

prelude

Macros§

bubble_err
bubble_into
from_with_trace
rebubble_err

Structs§

Bubbled
DisplayTrace
Frame
OneLineTrace
Origin
Trace

Traits§

HasTrace

Functions§

bubble
map_err_with_trace
origin
rebubble
trace_frames

Attribute Macros§

traceable