pretty_panics

Crates.iopretty_panics
lib.rspretty_panics
version0.1.0
sourcesrc
created_at2024-08-23 08:58:46.215656
updated_at2024-08-23 08:58:46.215656
descriptionpretty panic messages
homepagehttps://github.com/bizarre/pretty_panic
repository
max_upload_size
id1348894
size8,398
Alex Adewole (bizarre)

documentation

README

pretty_panics

pretty_panics is a crate that provides an easy way to customize panic messages and error messages.

If use-default-features is enabled, pretty_panics will provide default formatters for panics and errors.

use pretty_panics::pretty_panic;

#[pretty_panic]
fn main() -> std::result::Result<(), SomeDisplayError> {
    ...
}
use pretty_panics::pretty_panic;
use thiserror::Error;

#[derive(Error, Debug)]
enum SimpleError {
    #[error("an error")]
    AnError
}

fn error_formatter(error: &SimpleError) -> String {
    format!("uhhh something broke guys... {error}")
}

#[pretty_panic(formatter = error_formatter)]
fn main() -> anyhow::Result<(), SimpleError> {
    Result::<(), SimpleError>::Err(SimpleError::AnError)?;
    Ok(())
}

caveats: caveats:

  • requires your main fn to return a result
  • you will lose the ability to get panic backtraces unless you implement your own formatter and include it
  • you probably shouldn't use this tbh LMAO
  • doesn't work with async main fns yet xd
Commit count: 0

cargo fmt