#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

#1175 in HTTP server

Download history 15/week @ 2024-08-29 2/week @ 2024-09-05 4/week @ 2024-09-12 28/week @ 2024-09-19 27/week @ 2024-09-26 19/week @ 2024-10-03 9/week @ 2024-10-10 7/week @ 2024-10-17 9/week @ 2024-10-24 20/week @ 2024-10-31 20/week @ 2024-11-07 74/week @ 2024-11-14 64/week @ 2024-11-21 54/week @ 2024-11-28 51/week @ 2024-12-05 62/week @ 2024-12-12

242 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–49MB
~792K SLoC