Skip to content
Permalink
Browse files

Fix silent error and add custom panic handler again

This is to work around Tokio's panic recovery feautre.
Ref tokio-rs/tokio#495
Ref tokio-rs/tokio#209
Ref denoland#1311
Fixes denoland#2097
  • Loading branch information...
ry committed Apr 11, 2019
1 parent 08ab0b0 commit dbf55fa12dd7b577c6f287aead125a1b5db831ae
Showing with 24 additions and 2 deletions.
  1. +7 −0 cli/compiler.rs
  2. +7 −0 cli/main.rs
  3. +9 −1 cli/tokio_util.rs
  4. +1 −1 cli/worker.rs
@@ -111,6 +111,13 @@ fn lazy_start(parent_state: ThreadSafeState) -> ResourceId {

let mut runtime = C_RUNTIME.lock().unwrap();
runtime.spawn(lazy(move || {
// Tokio swallows panics. In order to actually crash when we panic, we
// have to set this custom hook.
std::panic::set_hook(Box::new(|panic_info| {
eprintln!("{}", panic_info.to_string());
std::process::abort();
}));

worker.then(move |result| -> Result<(), ()> {
// Close resource so the future created by
// handle_worker_message_stream exits
@@ -75,6 +75,13 @@ where
}

fn main() {
// Tokio swallows panics. In order to actually crash when we panic, we have
// to set this custom hook.
std::panic::set_hook(Box::new(|panic_info| {
eprintln!("{}", panic_info.to_string());
std::process::abort();
}));

#[cfg(windows)]
ansi_term::enable_ansi_support().ok(); // For Windows 10

@@ -40,7 +40,15 @@ where
let rt = tokio::runtime::Runtime::new().unwrap();
let mut executor = rt.executor();
let mut enter = tokio_executor::enter().expect("Multiple executors at once");
tokio_executor::with_default(&mut executor, &mut enter, move |_enter| f());
tokio_executor::with_default(&mut executor, &mut enter, move |_enter| {
// Tokio swallows panics. In order to actually crash when we panic, we
// have to set this custom hook.
std::panic::set_hook(Box::new(|panic_info| {
eprintln!("{}", panic_info.to_string());
std::process::abort();
}));
f()
});
}

#[derive(Debug)]
@@ -324,7 +324,7 @@ mod tests {
onmessage = function(e) {
console.log("msg from main script", e.data);
if (e.data == "exit") {
close();
delete window.onmessage;
return;
} else {
console.assert(e.data === "hi");

0 comments on commit dbf55fa

Please sign in to comment.
You can’t perform that action at this time.