emit-rs / emit

Developer-first diagnostics for Rust applications
https://emit-rs.io
Apache License 2.0
128 stars 2 forks source link

return in spans breaks ok_lvl and err_lvl #84

Closed KodrAus closed 2 months ago

KodrAus commented 2 months ago

This example:

#[emit::info_span(err_lvl: "warn", "Greeting {#[emit::as_serde] user}")]
fn greet(user: &User) -> Result<(), std::io::Error> {
    if user.name == "Mars" {
        return Err(std::io::Error::new(std::io::ErrorKind::Other, "refusing to greet user"));
    }

    emit::info!("Hello, {#[emit::as_serde] user}!");

    Ok(())
}

doesn't emit with the warn error level because the return statement returns before the level handling. We need to wrap the generated code in a closure.