From 8684c2d7d8df9a5b2b2dbf68fba5386879f3061f Mon Sep 17 00:00:00 2001 From: Gustavo Nofoente Date: Sat, 31 May 2025 11:00:49 -0300 Subject: [PATCH] Added "Error.captureStackTrace" to avoid overwriting error.stack --- lib/types/json.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/types/json.js b/lib/types/json.js index 078ce710..e5d3f009 100644 --- a/lib/types/json.js +++ b/lib/types/json.js @@ -68,7 +68,9 @@ function json (options) { if (first !== '{' && first !== '[') { debug('strict violation') - throw createStrictSyntaxError(body, first) + var err = createStrictSyntaxError(body, first) + Error.captureStackTrace(err) + throw err } } @@ -198,9 +200,6 @@ function normalizeJsonSyntaxError (error, obj) { } } - // replace stack before message for Node.js 0.10 and below - error.stack = obj.stack.replace(error.message, obj.message) error.message = obj.message - return error }