error_hook

Crates.ioerror_hook
lib.rserror_hook
version0.2.3
sourcesrc
created_at2023-03-04 04:58:47.604744
updated_at2023-03-04 23:31:43.474849
descriptionerror hook
homepage
repositoryhttps://github.com/LoliGothick/error_hook
max_upload_size
id800370
size7,226
Mitama (loliGothicK)

documentation

README

error_hook

This library supplements errors on a per-function basis and executes hooks.

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
Commit count: 15

cargo fmt