err-as-you-go crate - anyhow meets thiserror

205 points drymud64

I've just published a macro I'm particularly proud of, which generates error variants for you as you write code.

#[err_as_you_go]
pub fn foo() -> Result<(), FooError> {
    some_file_io().map(|e|
        err!(FileIoFailed(std::io::Error = e)) // here
    )?;
    
    if some_condition() {
        return Err(err!(ConditionFailed));     // and here
    }

    if count() > 1 {
        return Err(err!(CountTooBig {
            count: usize = count(),            // also here
        }));
    }

    Ok(())
}

The macro will generate a \pub enum FooError\\ with the requested variants.

Check out the docs for how you could integrate this with thiserror to easy-to-write, but application-friendly error handling :).

\- https://docs.rs/err-as-you-go

\- https://crates.io/crates/err-as-you-go

\- https://github.com/aatifsyed/err-as-you-go