fatal 0.1.1

End-user friendly panics.
Documentation
  • Coverage
  • 90.91%
    10 out of 11 items documented0 out of 5 items with examples
  • Size
  • Source code size: 9.41 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.42 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • hgalant/fatal.rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • hgalant

Utilities for reporting fatal errors and exiting with an error code.

The behavior in this crate is different than the one in panic!-based exits, in that the ones here are suited for display to end-users, i.e. no "thread main panicked at", no backtrace mentions, etc.

Usage

For unwrapping Results:

For aborting:

(Pseudo-)Example:

use fatal::UnwrapExt;

const DB_CONSTR_VAR: &str = "DB_CONNECTION_STRING";

fn main() {
    println!("Connecting..");
    let constr: String = fatal::unwrap_message!(std::env::var(DB_CONSTR_VAR), "failed to read the `{}` environment variable", DB_CONSTR_VAR);
    // when doesn't exist, will print: "Error: failed to read the `DB_CONNECTION_STRING` environment variable (environment variable not found)"
    let db: Database = Database::connect(&constr).expect_fatal("failed to connect to database");
    // would also include the actual error as above.

    println!("Querying total users..");
    println!("Total users: {}", db.query_total_users().unwrap_fatal());
}