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: https://github.com/nodejs/node/pull/26685 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
parent
3b5773fee3
commit
63e13fd220
@ -1373,6 +1373,7 @@ function format(...args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const firstErrorLine = (error) => error.message.split('\n')[0];
|
||||||
let CIRCULAR_ERROR_MESSAGE;
|
let CIRCULAR_ERROR_MESSAGE;
|
||||||
function tryStringify(arg) {
|
function tryStringify(arg) {
|
||||||
try {
|
try {
|
||||||
@ -1383,11 +1384,13 @@ function tryStringify(arg) {
|
|||||||
try {
|
try {
|
||||||
const a = {}; a.a = a; JSON.stringify(a);
|
const a = {}; a.a = a; JSON.stringify(a);
|
||||||
} catch (err) {
|
} 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]';
|
return '[Circular]';
|
||||||
|
}
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user