summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2023-04-27 22:36:49 +0100
committerGitHub <noreply@github.com>2023-04-27 23:36:49 +0200
commit504482dadd4d8cd9e4105d56ed86802906767f39 (patch)
treeacacb80e50ccfae578822dda63a3ec9e61108d60 /core
parent6cd62ea5e969de258b1d308daf5bec91e73e79d3 (diff)
fix(repl): print unhandled rejections and event errors (#18878)
Fixes #8858. Fixes #8869. ``` $ target/debug/deno Deno 1.32.5 exit using ctrl+d, ctrl+c, or close() REPL is running with all permissions allowed. To specify permissions, run `deno repl` with allow flags. > Promise.reject(new Error("bar")); Promise { <rejected> Error: bar at <anonymous>:2:16 } Uncaught (in promise) Error: bar at <anonymous>:2:16 > reportError(new Error("baz")); undefined Uncaught Error: baz at <anonymous>:2:13 >
Diffstat (limited to 'core')
-rw-r--r--core/inspector.rs29
-rw-r--r--core/ops_builtin_v8.rs3
-rw-r--r--core/realm.rs10
3 files changed, 40 insertions, 2 deletions
diff --git a/core/inspector.rs b/core/inspector.rs
index b0a55cf12..22d150154 100644
--- a/core/inspector.rs
+++ b/core/inspector.rs
@@ -231,6 +231,35 @@ impl JsRuntimeInspector {
.context_destroyed(context);
}
+ pub fn exception_thrown(
+ &self,
+ scope: &mut HandleScope,
+ exception: v8::Local<'_, v8::Value>,
+ in_promise: bool,
+ ) {
+ let context = scope.get_current_context();
+ let message = v8::Exception::create_message(scope, exception);
+ let stack_trace = message.get_stack_trace(scope).unwrap();
+ let mut v8_inspector_ref = self.v8_inspector.borrow_mut();
+ let v8_inspector = v8_inspector_ref.as_mut().unwrap();
+ let stack_trace = v8_inspector.create_stack_trace(stack_trace);
+ v8_inspector.exception_thrown(
+ context,
+ if in_promise {
+ v8::inspector::StringView::from("Uncaught (in promise)".as_bytes())
+ } else {
+ v8::inspector::StringView::from("Uncaught".as_bytes())
+ },
+ exception,
+ v8::inspector::StringView::from("".as_bytes()),
+ v8::inspector::StringView::from("".as_bytes()),
+ 0,
+ 0,
+ stack_trace,
+ 0,
+ );
+ }
+
pub fn has_active_sessions(&self) -> bool {
self.sessions.borrow().has_active_sessions()
}
diff --git a/core/ops_builtin_v8.rs b/core/ops_builtin_v8.rs
index f4133f3b8..67cf1222f 100644
--- a/core/ops_builtin_v8.rs
+++ b/core/ops_builtin_v8.rs
@@ -715,8 +715,7 @@ fn op_dispatch_exception(
let mut state = state_rc.borrow_mut();
if let Some(inspector) = &state.inspector {
let inspector = inspector.borrow();
- // TODO(nayeemrmn): Send exception message to inspector sessions here.
-
+ inspector.exception_thrown(scope, exception.v8_value, false);
// This indicates that the op is being called from a REPL. Skip termination.
if inspector.is_dispatching_message() {
return;
diff --git a/core/realm.rs b/core/realm.rs
index 08a550294..f907553f0 100644
--- a/core/realm.rs
+++ b/core/realm.rs
@@ -4,6 +4,7 @@ use crate::bindings;
use crate::modules::ModuleCode;
use crate::ops::OpCtx;
use crate::runtime::exception_to_err_result;
+use crate::JsRuntime;
use anyhow::Error;
use std::cell::RefCell;
use std::collections::HashMap;
@@ -288,6 +289,15 @@ impl<'s> JsRealmLocal<'s> {
drop(context_state);
let exception = v8::Local::new(scope, handle);
+ let state_rc = JsRuntime::state(scope);
+ let state = state_rc.borrow();
+ if let Some(inspector) = &state.inspector {
+ let inspector = inspector.borrow();
+ inspector.exception_thrown(scope, exception, true);
+ if inspector.has_blocking_sessions() {
+ return Ok(());
+ }
+ }
exception_to_err_result(scope, exception, true)
}
}