chillpill 0.2.0

A more powerful (and more restrictive) `std::panic::catch_unwind`
Documentation
  • Coverage
  • 100%
    13 out of 13 items documented1 out of 4 items with examples
  • Size
  • Source code size: 54.09 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.15 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • ijchen/chillpill
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ijchen

Chillpill

GitHub crates.io docs.rs License

A more powerful (and more restrictive) std::panic::catch_unwind.

chillpill::catch is able to suppress the default panic message printed to stderr and return the source code location (file, line, and column) of the panic, at the cost of requiring that no other code modifies the global panic hook during its execution.

See the chillpill::catch documentation for a full list of differences from std::panic::catch_unwind, and more information on the panic hook restriction.

Example Usage

chillpill::catch is a drop-in replacement for std::panic::catch_unwind:

use chillpill::{PanicData, PanicLocation};

fn main() {
    // The API of `chillpill::catch` is the same as `std::panic::catch_unwind`
    //
    // The important differences are outlined in the documentation for `catch`,
    // but this example demonstrates that panic messages are suppressed, and the
    // location of the panic (file, line, and column) are available at runtime.
    let panic_result: Result<(), PanicData> = chillpill::catch(|| {
        // You won't see this message on stderr, chillpill prevents panic output
        panic!("Uh oh, I'm freaking out!!!");
    });

    let panic_data = panic_result.unwrap_err();
    assert_eq!(
        panic_data.payload_as_string(),
        Some("Uh oh, I'm freaking out!!!")
    );

    let PanicLocation { file, line, col } = panic_data.location.unwrap();
    println!("The panic occurred in {file} on line {line}, column {col}.");
}
$ cargo run
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.00s
     Running `target/x86_64-unknown-linux-gnu/debug/example`
The panic occurred in src/main.rs on line 11, column 9.

License

Licensed under either of:

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.