gevi_error

Crates.iogevi_error
lib.rsgevi_error
version1.0.0
created_at2025-11-14 13:57:27.573136+00
updated_at2025-11-14 13:57:27.573136+00
descriptionA flavor of error types and error handling that I like
homepagehttps://gitlab.com/d5b4b2/gevi_error
repositoryhttps://gitlab.com/d5b4b2/gevi_error
max_upload_size
id1932899
size12,325
(6aa476)

documentation

https://docs.rs/gevi_error

README

A flavor of error types and error handling that I like.

Example

Use error! to scaffold your error who will be called Error.

use ::std::path::Path;

::gevi_error::error! {
    ReadFile(()),
    Http(u64),
}

impl Error {
    pub(crate) fn read_file<T>(path: T, error: ::std::io::Error) -> Self where T: AsRef<Path> {
        Error::ReadFile(
            Inner {
                message: format!("Failed to read from {}", path.as_ref().display()),
                cause: Some(Box::new(error)),
            },
            ()
        )
    }

    pub(crate) fn http(code: u64) -> Self {
        Error::Http(
            Inner {
                message: format!("Server responded with code {code}"),
                cause: None,
            },
            code
        )
    }
}

Wrap the main function to print the error trace when the program errors.

fn main() -> ::std::process::ExitCode {
    Error::wrap(try_main)
}

fn try_main() -> Result<(), Error> {
    // Your code
    Ok(())
}
Commit count: 0

cargo fmt