Skip to content

Commit

Permalink
Merge pull request #1436 from messense/panic-hook
Browse files Browse the repository at this point in the history
Add a user-friendly panic hook
  • Loading branch information
messense authored Jan 30, 2023
2 parents 8fb0931 + 82c4fb4 commit 5dcfd70
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,32 @@ fn run() -> Result<()> {
Ok(())
}

#[cfg(not(debug_assertions))]
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() {
#[cfg(not(debug_assertions))]
setup_panic_hook();

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

0 comments on commit 5dcfd70

Please sign in to comment.