cmd_error

Crates.iocmd_error
lib.rscmd_error
version1.0.0
created_at2022-12-13 23:56:56.832303+00
updated_at2022-12-13 23:56:56.832303+00
descriptionSimple crate to print an error message and exit while unwrapping Options and Results
homepage
repositoryhttps://github.com/AlexanderHarrison/cmd_error
max_upload_size
id736214
size15,033
Aitch (AlexanderHarrison)

documentation

README

When unwrapping Options and Results it's oddly annoying to print a simple error message and exit. This crate introduces the ErrExit trait which allows exactly that.

For example,

use cmd_error::ErrExit;

fn main() {
    let path = std::env::args().nth(1)
        .unwrap_exit("file path not passed");
    
    let file = std::fs::read_to_string(&path)
        .unwrap_exit(&format!("file {} not found", path));

    // ...
}

Why not use expect? Panic message aren't for users, they're for the programmers.

This crate also exports the function print_err_and_exit which unsurprisingly prints an error message and exits.

Exits with an exit code of 1. Errors are printed to stderr.

Commit count: 8

cargo fmt