From 1645e04139f9101aa7bcbd5379c6d43eb50b02dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Z=C3=BCnd?= Date: Thu, 24 Jan 2019 14:51:33 +0100 Subject: [PATCH] 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. --- lib/internal/util/inspect.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index 4cee2d8b9fb4a3..49763fe7d2e299 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -1383,6 +1383,7 @@ function format(...args) { } +const firstErrorLine = (error) => error.message.split('\n')[0]; let CIRCULAR_ERROR_MESSAGE; function tryStringify(arg) { try { @@ -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; } }