Skip to content

Commit 63e13fd

Browse files
szuendrefack
authored andcommitted
util: only the first line of the error message
V8 extends the error message for JSON#stringify when encountering circular structures. The first line of the new error message is equivalent to the old error message and stays the same across all circular structure errors. PR-URL: #26685 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent 3b5773f commit 63e13fd

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/internal/util/inspect.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,7 @@ function format(...args) {
13731373
}
13741374

13751375

1376+
const firstErrorLine = (error) => error.message.split('\n')[0];
13761377
let CIRCULAR_ERROR_MESSAGE;
13771378
function tryStringify(arg) {
13781379
try {
@@ -1383,11 +1384,13 @@ function tryStringify(arg) {
13831384
try {
13841385
const a = {}; a.a = a; JSON.stringify(a);
13851386
} catch (err) {
1386-
CIRCULAR_ERROR_MESSAGE = err.message;
1387+
CIRCULAR_ERROR_MESSAGE = firstErrorLine(err);
13871388
}
13881389
}
1389-
if (err.name === 'TypeError' && err.message === CIRCULAR_ERROR_MESSAGE)
1390+
if (err.name === 'TypeError' &&
1391+
firstErrorLine(err) === CIRCULAR_ERROR_MESSAGE) {
13901392
return '[Circular]';
1393+
}
13911394
throw err;
13921395
}
13931396
}

0 commit comments

Comments
 (0)