From 76adbdb704370b15ed00119cbccc93cd5b936452 Mon Sep 17 00:00:00 2001 From: ozwaldorf Date: Thu, 9 May 2024 09:06:05 -0400 Subject: [PATCH] fix(js): catch and return errors in main function call --- services/js-poc/src/runtime/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/js-poc/src/runtime/mod.rs b/services/js-poc/src/runtime/mod.rs index 2af4f52c8..db9c147d7 100644 --- a/services/js-poc/src/runtime/mod.rs +++ b/services/js-poc/src/runtime/mod.rs @@ -112,7 +112,6 @@ impl Runtime { ], startup_snapshot: Some(SNAPSHOT), op_metrics_factory_fn: Some(tape.op_metrics_factory_fn()), - // Heap initializes with 1KiB, maxes out at 10MiB create_params: Some(CreateParams::default().heap_limits(HEAP_INIT, HEAP_LIMIT)), module_loader: Some(Rc::new(module_loader::node_crypto())), ..Default::default() @@ -170,6 +169,7 @@ impl Runtime { { let main = self.deno.get_module_namespace(id)?; let scope = &mut self.deno.handle_scope(); + let scope = &mut v8::TryCatch::new(scope); let main_local = v8::Local::new(scope, main); // Get bootstrap function pointer @@ -191,6 +191,11 @@ impl Runtime { // call function and move response into a global ref let Some(res) = main_fn.call(scope, undefined.into(), &[param]) else { + if let Some(exception) = scope.exception() { + let error = deno_core::error::JsError::from_v8_exception(scope, exception); + return Err(error.into()); + } + return Ok(None); }; Ok(Some(Global::new(scope, res)))