diff options
author | Luca Casonato <hello@lcas.dev> | 2021-12-20 14:49:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-20 14:49:05 +0100 |
commit | 17d81ad2ef0001f862ba0a324e2f4d28f1cfdc78 (patch) | |
tree | 5bf0f2f291d693484a5fc490ba45937907b415ec | |
parent | ef95d7b1e973ca544af3f96876c3c224bca6ab32 (diff) |
chore: add custom panic message (#13145)
-rw-r--r-- | cli/main.rs | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/cli/main.rs b/cli/main.rs index 9a613fb64..6c1e782a7 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -1444,11 +1444,29 @@ fn get_subcommand( } } -fn setup_exit_process_panic_hook() { - // tokio does not exit the process when a task panics, so we - // define a custom panic hook to implement this behaviour +fn setup_panic_hook() { + // This function does two things inside of the panic hook: + // - Tokio does not exit the process when a task panics, so we define a custom + // panic hook to implement this behaviour. + // - We print a message to stderr to indicate that this is a bug in Deno, and + // should be reported to us. let orig_hook = std::panic::take_hook(); std::panic::set_hook(Box::new(move |panic_info| { + eprintln!("\n============================================================"); + eprintln!("Deno has panicked. This is a bug in Deno. Please report this"); + eprintln!("at https://github.com/denoland/deno/issues/new."); + eprintln!("If you can reliably reproduce this panic, include the"); + eprintln!("reproduction steps and re-run with the RUST_BACKTRACE=1 env"); + eprintln!("var set and include the backtrace in your report."); + eprintln!(); + eprintln!( + "Platform: {} {}", + std::env::consts::OS, + std::env::consts::ARCH + ); + eprintln!("Version: {}", version::deno()); + eprintln!("Args: {:?}", std::env::args().collect::<Vec<_>>()); + eprintln!(); orig_hook(panic_info); std::process::exit(1); })); @@ -1465,7 +1483,7 @@ fn unwrap_or_exit<T>(result: Result<T, AnyError>) -> T { } pub fn main() { - setup_exit_process_panic_hook(); + setup_panic_hook(); unix_util::raise_fd_limit(); windows_util::ensure_stdio_open(); |