#error-context #exit #exiting #processes #gracefully #style #messages

eoe

This crate provides utilities for exiting processes on errors gracefully

6 releases

Uses new Rust 2024

new 0.3.1 Mar 21, 2025
0.3.0 Mar 21, 2025
0.2.0 Feb 28, 2025
0.1.2 Feb 27, 2025
0.1.1 Jul 14, 2024

#2 in #gracefully

Download history 1/week @ 2025-01-24 4/week @ 2025-01-31 69/week @ 2025-02-21 244/week @ 2025-02-28 6/week @ 2025-03-07

319 downloads per month
Used in thus-saith

MIT license

12KB
133 lines

Exit on Error

Crates.io Documentation License: MIT

This crate provides utilities for exiting processes on errors gracefully, leveraging anyhow to display detailed error context and chained messages.

Examples

Exiting on error:

use anyhow::{Context, anyhow};
use eoe::ExitOnError;

Err::<(), _>(anyhow!("Mm-noom-ba-deh"))
    .context("Doom-boom-ba-beh")
    .context("Doo-boo-boom-ba-beh-beh")
    .exit_on_error();

exit on error

Or if you prefer the word quit:

use anyhow::{Context, anyhow};
use eoe::QuitOnError;

Err::<(), _>(anyhow!("Mm-ba-ba-beh, mm-ba-ba-beh"))
    .context("Dee-day-da, ee-day-da")
    .quit_on_error();

quit on error

Messages are customizable:

use eoe::{ExitOnError, Segment, Style};

let _ = eoe::ERROR.set(Segment {
    style: Style::new().bold().blue(),
    value: "Watchin' some good friends screamin'",
});
let _ = eoe::SEP.set(Segment {
    style: Style::new(),
    value: " 😱 ",
});
let _ = eoe::MESSAGE_STYLE.set(Style::new().italic().yellow());
let _ = eoe::MESSAGE_ON_NONE.set("Let me out");

None::<()>.exit_on_error();

customized

Dependencies

~0.3–6.5MB
~38K SLoC