mirror of
https://github.com/denoland/deno
synced 2024-09-17 23:22:46 +00:00
fix: exit process on panic in a tokio task (#11942)
This commit is contained in:
parent
e3a484ae44
commit
4833103011
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 {
|
fn unwrap_or_exit<T>(result: Result<T, AnyError>) -> T {
|
||||||
match result {
|
match result {
|
||||||
Ok(value) => value,
|
Ok(value) => value,
|
||||||
|
@ -1237,6 +1247,7 @@ fn unwrap_or_exit<T>(result: Result<T, AnyError>) -> T {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
|
setup_exit_process_panic_hook();
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
colors::enable_ansi(); // For Windows 10
|
colors::enable_ansi(); // For Windows 10
|
||||||
unix_util::raise_fd_limit();
|
unix_util::raise_fd_limit();
|
||||||
|
|
Loading…
Reference in a new issue