From 39d98d3488a1b026fbe3e129fa799096284f1482 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Tue, 31 Jan 2023 16:10:19 +0100 Subject: [PATCH] Disable panic hook about reporting issues for debug builds In order to avoid confusing new developers. When a debug build panics chances are that the panic is caused by local changes and should in fact not be reported on GitHub. --- ruff_cli/src/main.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/ruff_cli/src/main.rs b/ruff_cli/src/main.rs index 1ff7e57721..23854c2b20 100644 --- a/ruff_cli/src/main.rs +++ b/ruff_cli/src/main.rs @@ -58,20 +58,23 @@ fn inner_main() -> Result { log_level_args, } = Args::parse_from(args); - let default_panic_hook = std::panic::take_hook(); - std::panic::set_hook(Box::new(move |info| { - eprintln!( - r#" + #[cfg(not(debug_assertions))] + { + let default_panic_hook = std::panic::take_hook(); + std::panic::set_hook(Box::new(move |info| { + eprintln!( + r#" {}: `ruff` crashed. This indicates a bug in `ruff`. If you could open an issue at: https://github.com/charliermarsh/ruff/issues/new?title=%5BPanic%5D quoting the executed command, along with the relevant file contents and `pyproject.toml` settings, we'd be very appreciative! "#, - "error".red().bold(), - ); - default_panic_hook(info); - })); + "error".red().bold(), + ); + default_panic_hook(info); + })); + } let log_level: LogLevel = (&log_level_args).into(); set_up_logging(&log_level)?;