instrumentisto / tracerr-rs

Custom compile time captured error tracing for Rust

Home Page:https://docs.rs/tracerr

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tracerr

crates.io Rust 1.72+ Unsafe Forbidden
CI Rust docs

API Docs | Changelog

Custom compile-time captured error tracing for Rust.

Usage

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();
# #[cfg(not(target_os = "windows"))]
assert_eq!(
    format!("{}\n{}", err, err.trace()),
    r"my error
error trace:
rust_out
  at src/lib.rs:7
rust_out
  at src/lib.rs:10",
);

let (val, trace) = err.split();
# #[cfg(not(target_os = "windows"))]
assert_eq!(
    format!("{}\n{}", val, trace),
    r"my error
error trace:
rust_out
  at src/lib.rs:7
rust_out
  at src/lib.rs:10",
);

License

Copyright © 2019-2024 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.

About

Custom compile time captured error tracing for Rust

https://docs.rs/tracerr

License:Other


Languages

Language:Rust 91.2%Language:Makefile 8.8%