From 994b6327d3af5721fa4fcf6fbfe856a6f6da79cf Mon Sep 17 00:00:00 2001 From: MujahedSafaa <168719085+MujahedSafaa@users.noreply.github.com> Date: Mon, 22 Jul 2024 14:18:49 +0300 Subject: fix(ext/console): Error Cause Not Inspect-Formatted when printed (#24526) This pull request addresses an issue where the Error.cause property was not formatted correctly when printed using console.log, leading to confusion. solution: Implemented a fix to ensure that Error.cause is formatted properly when printed by console.log, and the fix done by using JSON.stringify This PR fixes https://github.com/denoland/deno/issues/23416 --------- Signed-off-by: MujahedSafaa <168719085+MujahedSafaa@users.noreply.github.com> --- ext/console/01_console.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'ext/console') diff --git a/ext/console/01_console.js b/ext/console/01_console.js index 90f09d4d1..cffa72d8c 100644 --- a/ext/console/01_console.js +++ b/ext/console/01_console.js @@ -1484,12 +1484,18 @@ function inspectError(value, ctx) { finalMessage += `[${stack || ErrorPrototypeToString(value)}]`; } } + const doubleQuoteRegExp = new SafeRegExp('"', "g"); finalMessage += ArrayPrototypeJoin( ArrayPrototypeMap( causes, (cause) => "\nCaused by " + (MapPrototypeGet(refMap, cause) ?? "") + - (cause?.stack ?? cause), + (cause?.stack ?? + StringPrototypeReplace( + inspect(cause), + doubleQuoteRegExp, + "", + )), ), "", ); -- cgit v1.2.3