Crate not_so_human_panic

Source
Expand description

Panic messages for humans

Handles panics by calling std::panic::set_hook to make errors nice for humans.

§Differences from Human-Panic

While these two libraries are extremely similar, not-so-human-panic also tells your users why the program panicked. It also has some slight changes to wording, mostly to prod users to report whatever bug/problem they’ve found.

That said, human-panic may look less scary. If your panics are due to “truly” unexpected values, or your users are less technical, human-panic may be the better option!

§Quick Start

To begin, please add the library to your Rust project with cargo add not-so-human-panic. You can also edit your Cargo.toml manually!

Afterwards, you should use the library and stick it somewhere nice. An entrypoint like main is probably a good place to start!

use not_so_human_panic::setup_panic;

fn main() {
   // If you want different info than your Cargo.toml provides,
   // please fill out a "Metadata" struct with your information
   setup_panic!();

    // Fun little panic which will be happily explained
    panic!("oh hey im in the quick start :D");
}

fn main_but_with_metadata() {
    // If you want different info than what's in your Cargo.toml,
    // fill out a "Metadata" struct with some different values
    setup_panic!(Metadata {
      name: env!("CARGO_PKG_NAME").into(),
       version: env!("CARGO_PKG_VERSION").into(),
       authors: "Some Guy <someone-somewhere@farts.com>".into(),
       homepage: "github.com/someone/some-crate".into(),
    });

    panic!("ahhh you caught me!");
}

§Why?

When you’re building a CLI, polish is super important. Even though Rust is pretty great at safety, it’s not unheard of to access the wrong index in a vector or have an assert fail somewhere.

When an error eventually occurs, you probably will want to know about it. So instead of just providing an error message on the command line, we can create a call to action for people to submit a report.

This should empower people to engage in communication, lowering the chances people might get frustrated. And making it easier to figure out what might be causing bugs.

§Default Output

thread 'main' panicked at 'oops', examples/main.rs:2:3
note: Run with `RUST_BACKTRACE=1` for a backtrace.

§Not-So-Human-Panic Output

Well, this is embarrassing.

not-so-human-panic had a problem and crashed. It seems that the problem has to do with the following:
OMG EVERYTHING IS ON FIRE!!!

If you'd like, you can help us diagnose the problem! Please feel free to send us a crash report using the instructions below.

We have generated a report file at "/var/folders/zw/bpfvmq390lv2c6gn_6byyv0w0000gn/T/report-8351cad6-d2b5-4fe8-accd-1fcbf4538792.toml". Submit an issue or email with the subject of "single-panic-test Crash Report" and include the report as an attachment.

- Authors: Yoshua Wuyts <yoshuawuyts@gmail.com>
- Homepage: https://github.com/onkoe/not-so-human-panic

We take privacy very seriously - we don't perform any automated error collection. In order to improve the software, we rely on users like you to submit reports.

Thank you kindly!

Modules§

report
This module encapsulates the report of a failure event.

Macros§

metadata
Initialize Metadata
setup_panic
not-so-human-panic initialisation macro

Structs§

Metadata
A convenient metadata struct that describes a crate

Enums§

PanicStyle
Style of panic to be used

Functions§

handle_dump
Utility function which will handle dumping information to disk
print_msgcolor
Utility function that prints a message to our human users