Skip to content

Commit

Permalink
Handle errors thrown by reportError in queueMicrotask
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Sep 23, 2024
1 parent ba8a592 commit 62e8d9f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/workerd/api/global-scope.c++
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,20 @@ void ServiceWorkerGlobalScope::queueMicrotask(jsg::Lock& js, v8::Local<v8::Funct
return jsg::check(
function->Call(js.v8Context(), js.v8Null(), argv.size(), argv.data()));
}, [&](jsg::Value exception) {
reportError(js, jsg::JsValue(exception.getHandle(js)));
// The reportError call itself can potentially throw errors. Let's catch
// and report them as well.
js.tryCatch([&] { reportError(js, jsg::JsValue(exception.getHandle(js))); },
[&](jsg::Value exception) {
if (IoContext::hasCurrent()) {
// If we're running in a request context then we want to abort the
// request with the exception here.
IoContext::current().abort(js.exceptionToKj(kj::mv(exception)));
} else {
// If we're running outside of a request context. There's nothing to
// abort but we at least want to log the exception.
js.reportError(jsg::JsValue(exception.getHandle(js)));
}
});
return js.v8Undefined();
});
}));
Expand Down

0 comments on commit 62e8d9f

Please sign in to comment.