Skip to content

Commit 1645e04

Browse files
szuendryzokuken
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.
1 parent 62c2310 commit 1645e04

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/internal/util/inspect.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,7 @@ function format(...args) {
13831383
}
13841384

13851385

1386+
const firstErrorLine = (error) => error.message.split('\n')[0];
13861387
let CIRCULAR_ERROR_MESSAGE;
13871388
function tryStringify(arg) {
13881389
try {
@@ -1393,11 +1394,13 @@ function tryStringify(arg) {
13931394
try {
13941395
const a = {}; a.a = a; JSON.stringify(a);
13951396
} catch (err) {
1396-
CIRCULAR_ERROR_MESSAGE = err.message;
1397+
CIRCULAR_ERROR_MESSAGE = firstErrorLine(err);
13971398
}
13981399
}
1399-
if (err.name === 'TypeError' && err.message === CIRCULAR_ERROR_MESSAGE)
1400+
if (err.name === 'TypeError' &&
1401+
firstErrorLine(err) === CIRCULAR_ERROR_MESSAGE) {
14001402
return '[Circular]';
1403+
}
14011404
throw err;
14021405
}
14031406
}

0 commit comments

Comments
 (0)