snafu-tracing

Crates.iosnafu-tracing
lib.rssnafu-tracing
version0.8.3
created_at2025-04-21 13:04:45.851348+00
updated_at2025-04-21 13:18:54.499908+00
descriptionSnafu tracing is an error handling mechanism with pseudo-stack traces implemented through SNAFU, the proc macro trace_error, and the DebugTrace trait, inspired by GreptimeDB.
homepage
repositoryhttps://github.com/dancingpeanut/snafu-tracing
max_upload_size
id1642652
size6,803
(dancingpeanut)

documentation

README

snafu-tracing

Snafu tracing is an error handling mechanism with pseudo-stack traces implemented through SNAFU, the proc macro trace_error, and the DebugTrace trait, inspired by GreptimeDB.

Example

use snafu::Snafu;
use snafu_tracing::{DebugTrace, trace_error, quick_tracing};

pub type Result<T, E = Error> = std::result::Result<T, E>;

#[trace_error]
#[derive(Snafu, DebugTrace)]
#[snafu(module, context(suffix(false)), visibility(pub))]
pub enum Error {
    #[snafu(display("{_error}"))]
    Any { _error: String },
    #[snafu(display("{error_source}"))]
    Wrap {
        #[snafu(source(from(Box<dyn std::error::Error + Send + Sync>, |e| e)))]
        error_source: Box<dyn std::error::Error + Send + Sync>,
    },
}

quick_tracing!(anyerr, crate::error::Any);

pub fn hello_err() -> Result<()> {
    let _e = anyerr!("Any error test! {}", 123);
    Err(anyerr!("Any error test!"))
}

fn main() {
    let e = hello_err();
    println!("{:?}", e);
}

Or refer to: full example

References

  1. Rust 错误处理在 GreptimeDB 的实践 (Rust error handling practice in GreptimeDB). Strongly recommended. Google translation should be enough for non-Chinese speakers.
Commit count: 3

cargo fmt