mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
fix: exit process on panic in a tokio task (#11942)
This commit is contained in:
parent
e3a484ae44
commit
4833103011
1 changed files with 11 additions and 0 deletions
11
cli/main.rs
11
cli/main.rs
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue