Skip to content

Commit

Permalink
util: only the first line of the error message
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
szuend authored and ryzokuken committed Mar 16, 2019
1 parent 62c2310 commit 1645e04
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/internal/util/inspect.js
Expand Up @@ -1383,6 +1383,7 @@ function format(...args) {
}


const firstErrorLine = (error) => error.message.split('\n')[0];
let CIRCULAR_ERROR_MESSAGE;
function tryStringify(arg) {
try {
Expand All @@ -1393,11 +1394,13 @@ function tryStringify(arg) {
try {
const a = {}; a.a = a; JSON.stringify(a);
} catch (err) {
CIRCULAR_ERROR_MESSAGE = err.message;
CIRCULAR_ERROR_MESSAGE = firstErrorLine(err);
}
}
if (err.name === 'TypeError' && err.message === CIRCULAR_ERROR_MESSAGE)
if (err.name === 'TypeError' &&
firstErrorLine(err) === CIRCULAR_ERROR_MESSAGE) {
return '[Circular]';
}
throw err;
}
}
Expand Down

0 comments on commit 1645e04

Please sign in to comment.