Panic messages for humans. Wrapper around
std::panic::catch_unwind
to make errors nice for humans.
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.
txt
thread 'main' panicked at 'oops', examples/main.rs:2:3
note: Run with `RUST_BACKTRACE=1` for a backtrace.
```txt Well, this is embarrasing.
Example had a problem and crashed. To help us diagnose the problem you can send us a crash report.
Submit an issue to "github.com/example/main" or email "crash@example-corp.com" with the subject "Example Crash Report". Please include the report located at "/tmp/example/panic-2018-04-20.log" as an attachment.
Thank you kindly! ```
```rust extern crate human_panic;
humanpanic::catchunwind(|| { panic!("something went wrong"); }); ```
Because we rely on std::panic::catch_unwind
, we inherit some of the same
limitations. More specifically: we can only catch unwinding panics, not
aborts. This
should be alright for most cases, but it's good to be aware of what the
limitations are.
sh
$ cargo add human-panic
MIT OR Apache-2.0