summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorKevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com>2019-12-19 21:04:14 -0800
committerRy Dahl <ry@tinyclouds.org>2019-12-20 00:04:14 -0500
commit9ef0b18eb0b4c337ccfc8d0add36bec6b657262f (patch)
tree62bc08da0245b8fd7f350480c3ad94319457a7be /cli
parentfcae4a7c0dc74701f3b1919bfd76cfdc1a0321ed (diff)
repl: do not crash on async op reject (#3527)
Diffstat (limited to 'cli')
-rw-r--r--cli/lib.rs5
-rw-r--r--cli/worker.rs8
2 files changed, 13 insertions, 0 deletions
diff --git a/cli/lib.rs b/cli/lib.rs
index df4cbbdf0..b191d5e87 100644
--- a/cli/lib.rs
+++ b/cli/lib.rs
@@ -349,6 +349,11 @@ fn bundle_command(flags: DenoFlags) {
fn run_repl(flags: DenoFlags) {
let (mut worker, _state) = create_worker_and_state(flags);
+ // Make repl continue to function under uncaught async errors.
+ worker.set_error_handler(Box::new(|err| {
+ eprintln!("{}", err.to_string());
+ Ok(())
+ }));
// Setup runtime.
js_check(worker.execute("denoMain()"));
let main_future = async move {
diff --git a/cli/worker.rs b/cli/worker.rs
index 814e7f440..e35458d39 100644
--- a/cli/worker.rs
+++ b/cli/worker.rs
@@ -96,6 +96,14 @@ impl Worker {
}
}
+ pub fn set_error_handler(
+ &mut self,
+ handler: Box<dyn FnMut(ErrBox) -> Result<(), ErrBox>>,
+ ) {
+ let mut i = self.isolate.lock().unwrap();
+ i.set_error_handler(handler);
+ }
+
/// Same as execute2() but the filename defaults to "$CWD/__anonymous__".
pub fn execute(&mut self, js_source: &str) -> Result<(), ErrBox> {
let path = env::current_dir().unwrap().join("__anonymous__");