1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

fix: exit process on panic in a tokio task (#11942)

This commit is contained in:
David Sherret 2021-09-07 19:34:27 -04:00 committed by GitHub
parent e3a484ae44
commit 4833103011
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1226,6 +1226,16 @@ 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
let orig_hook = std::panic::take_hook();
std::panic::set_hook(Box::new(move |panic_info| {
orig_hook(panic_info);
std::process::exit(1);
}));
}
fn unwrap_or_exit<T>(result: Result<T, AnyError>) -> T {
match result {
Ok(value) => value,
@ -1237,6 +1247,7 @@ fn unwrap_or_exit<T>(result: Result<T, AnyError>) -> T {
}
pub fn main() {
setup_exit_process_panic_hook();
#[cfg(windows)]
colors::enable_ansi(); // For Windows 10
unix_util::raise_fd_limit();