summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSimon Zünd <szuend@chromium.org>2019-01-24 14:51:33 +0100
committerRefael Ackermann <refack@gmail.com>2019-03-28 16:39:25 -0400
commit63e13fd2209ac407ee70505dbffaa4e53138614b (patch)
treed1e9e1f73fc278cbe5b538a213845bd1705ee6fc /lib
parent3b5773fee389c52077bd9f2dd324739af27fb6b5 (diff)
downloadandroid-node-v8-63e13fd2209ac407ee70505dbffaa4e53138614b.tar.gz
android-node-v8-63e13fd2209ac407ee70505dbffaa4e53138614b.tar.bz2
android-node-v8-63e13fd2209ac407ee70505dbffaa4e53138614b.zip
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/util/inspect.js7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js
index 06578cb56e..e8161f3b52 100644
--- a/lib/internal/util/inspect.js
+++ b/lib/internal/util/inspect.js
@@ -1373,6 +1373,7 @@ function format(...args) {
}
+const firstErrorLine = (error) => error.message.split('\n')[0];
let CIRCULAR_ERROR_MESSAGE;
function tryStringify(arg) {
try {
@@ -1383,11 +1384,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;
}
}