Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorlegendecas <legendecas@gmail.com>2021-04-06 06:49:38 +0300
committerMichaël Zasso <targos@protonmail.com>2021-05-01 13:31:17 +0300
commitb5ad655c6be326ccfbcc9290bea26f413085d6b0 (patch)
tree716a411978e76ebe094cc237fc71be02eedb29f7 /lib
parent079d90b9f31bf93bbe685c3970e0e1bd02f2afdd (diff)
lib: properly process JavaScript exceptions on async_hooks fatal error
JavaScript exceptions could be arbitrary values. PR-URL: https://github.com/nodejs/node/pull/38106 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/async_hooks.js12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js
index 84e73280cce..28d0655d97c 100644
--- a/lib/internal/async_hooks.js
+++ b/lib/internal/async_hooks.js
@@ -99,6 +99,9 @@ const { kInit, kBefore, kAfter, kDestroy, kTotals, kPromiseResolve,
const { async_id_symbol,
trigger_async_id_symbol } = internalBinding('symbols');
+// Lazy load of internal/util/inspect;
+let inspect;
+
// Used in AsyncHook and AsyncResource.
const init_symbol = Symbol('init');
const before_symbol = Symbol('before');
@@ -155,12 +158,17 @@ function executionAsyncResource() {
return lookupPublicResource(resource);
}
+function inspectExceptionValue(e) {
+ inspect = inspect ?? require('internal/util/inspect').inspect;
+ return { message: inspect(e) };
+}
+
// Used to fatally abort the process if a callback throws.
function fatalError(e) {
- if (typeof e.stack === 'string') {
+ if (typeof e?.stack === 'string') {
process._rawDebug(e.stack);
} else {
- const o = { message: e };
+ const o = inspectExceptionValue(e);
ErrorCaptureStackTrace(o, fatalError);
process._rawDebug(o.stack);
}