summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/console/01_console.js8
-rw-r--r--tests/unit/console_test.ts16
2 files changed, 23 insertions, 1 deletions
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,
+ "",
+ )),
),
"",
);
diff --git a/tests/unit/console_test.ts b/tests/unit/console_test.ts
index 49960f663..4c9378bd4 100644
--- a/tests/unit/console_test.ts
+++ b/tests/unit/console_test.ts
@@ -2206,6 +2206,22 @@ Deno.test(function inspectErrorCircular() {
);
});
+Deno.test(function inspectErrorWithCauseFormat() {
+ const error = new Error("This is an error", {
+ cause: {
+ code: 100500,
+ },
+ });
+ assertStringIncludes(
+ stripColor(Deno.inspect(error)),
+ "Error: This is an error",
+ );
+ assertStringIncludes(
+ stripColor(Deno.inspect(error)),
+ "Caused by { code: 100500 }",
+ );
+});
+
Deno.test(function inspectColors() {
assertEquals(Deno.inspect(1), "1");
assertStringIncludes(Deno.inspect(1, { colors: true }), "\x1b[");