Skip to content

Commit

Permalink
Add a user-friendly panic hook
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Jan 30, 2023
1 parent 8fb0931 commit aa10b9f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,30 @@ fn run() -> Result<()> {
Ok(())
}

fn setup_panic_hook() {
let default_hook = std::panic::take_hook();
std::panic::set_hook(Box::new(move |panic_info| {
eprintln!("\n====================================================================");
eprintln!("maturin has panicked. This is a bug in maturin. Please report this");
eprintln!("at https://github.com/PyO3/maturin/issues/new/choose.");
eprintln!("If you can reliably reproduce this panic, include the");
eprintln!("reproduction steps and re-run with the RUST_BACKTRACE=1 environment");
eprintln!("variable set and include the backtrace in your report.");
eprintln!();
eprintln!("Platform: {} {}", env::consts::OS, env::consts::ARCH);
eprintln!("Version: {}", env!("CARGO_PKG_VERSION"));
eprintln!("Args: {}", env::args().collect::<Vec<_>>().join(" "));
eprintln!();
default_hook(panic_info);
// Rust set exit code to 101 when the process panicked,
// so here we use the same exit code
std::process::exit(101);
}));
}

fn main() {
setup_panic_hook();

if let Err(e) = run() {
eprintln!("💥 maturin failed");
for cause in e.chain() {
Expand Down

0 comments on commit aa10b9f

Please sign in to comment.