diff --git a/lib/internal/process/task_queues.js b/lib/internal/process/task_queues.js index f9e72c67075f94..bec23352eb4518 100644 --- a/lib/internal/process/task_queues.js +++ b/lib/internal/process/task_queues.js @@ -15,6 +15,10 @@ const { enqueueMicrotask } = internalBinding('task_queue'); +const { + triggerUncaughtException +} = internalBinding('errors'); + const { setHasRejectionToWarn, hasRejectionToWarn, @@ -147,6 +151,11 @@ function runMicrotask() { const callback = this.callback; try { callback(); + } catch (error) { + // runInAsyncScope() swallows the error so we need to catch + // it and handle it here. + triggerUncaughtException(error, false /* fromPromise */); + } finally { this.emitDestroy(); }