#rocket #error-handling #web-programming-rocket

rocket-errors

A library for handling errors with anyhow and eyre in Rocket applications

1 unstable release

0.1.0 Dec 26, 2023

#1092 in HTTP server

46 downloads per month

MIT license

15KB

rocket-errors

A crate that can handle anyhow and eyre on Rocket v0.5+.

Usage example

Please see actual examples in the /examples directory.

anyhow

use rocket::{get, routes};
use rocket_errors::anyhow;

#[get("/")]
pub fn health_check() -> anyhow::Result<&'static str> {
    Ok("Hello, world!")
}

#[rocket::main]
async fn main() -> anyhow::Result<()> {
    let _ = rocket::build()
        .mount("/hc", routes![health_check])
        .launch()
        .await?;
    Ok(())
}

eyre

use rocket::{get, routes};
use rocket_errors::eyre;

#[get("/")]
pub fn health_check() -> eyre::Result<&'static str> {
    Ok("Hello, world!")
}

#[rocket::main]
async fn main() -> eyre::Result<()> {
    let _ = rocket::build()
        .mount("/hc", routes![health_check])
        .launch()
        .await?;
    Ok(())
}

Install

anyhow

anyhow is turned on by default. You just need to add a dependency to this crate:

rocket-errors = { version = "0.1" }

eyre

Using eyre is optional. You would like to use it, you need to add a dependency to this crate with a feature flag.

rocket-errors = { version = "0.1", features = ["eyre"] }

License

This project is licensed under the MIT license.

Dependencies

~15–46MB
~790K SLoC