Custom compile-time captured error tracing for Rust.
The common rule:
- Use macro to capture trace frame in the invocation place.
use tracerr::Traced;
let err = tracerr::new!("my error"); // captures frame
let res: Result<(), _> = Err(err)
.map_err(tracerr::wrap!()); // captures frame
let err: Traced<&'static str> = res.unwrap_err();
assert_eq!(
format!("{err}\n{}", err.trace()),
r"my error
error trace:
rust_out
at src/lib.rs:6
rust_out
at src/lib.rs:9",
);
let (val, trace) = err.split();
assert_eq!(
format!("{val}\n{trace}"),
r"my error
error trace:
rust_out
at src/lib.rs:6
rust_out
at src/lib.rs:9",
);
Copyright © 2019-2025 Instrumentisto Team, https://github.com/instrumentisto
This software is subject to the terms of the Blue Oak Model License 1.0.0. If a copy of the BlueOak-1.0.0 license was not distributed with this file, You can obtain one at https://blueoakcouncil.org/license/1.0.0.