3 releases

0.1.2 Mar 4, 2023
0.1.1 Mar 4, 2023
0.1.0 Mar 4, 2023

#13 in #re-exported

Download history 4/week @ 2024-02-18 11/week @ 2024-02-25 1/week @ 2024-03-03 5/week @ 2024-03-10 54/week @ 2024-03-31

59 downloads per month
Used in error_hook

ISC license

4KB

error_hook_attr

This library supplements hook macro attribute to hook error conversion (please use the re-exported macro from error_hook via feature attribute).

Example

use error_hook::{self, hook};

#[hook(e => tracing::error!("{e}"))] // <-
#[tracing::instrument]
async fn test(a: i32, b: i32) -> error_hook::Result<i32> {
    a.checked_mul(b).ok_or(anyhow::anyhow!("overflow"))
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt()
        .with_max_level(tracing::Level::INFO)
        .init();

    let ans = test(888888888, 888888888).await?;
    println!("{ans}");

    Ok(())
}

output

2023-03-04T06:23:33.048087Z ERROR test{a=888888888 b=888888888}: example: overflow

lib.rs:

This library supplements hook macro attribute to hook error conversion (please use the re-exported macro from error_hook via feature attribute).

Dependencies

~1.5MB
~34K SLoC