Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ext/console/01_console.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
"",
)),
Comment on lines +1494 to +1498
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inspect does not insert superfluous double quotes like JSON.stringify does, so the replace call can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried tor remove the replace with the new code inspect but the test inspectErrorCircular failed on this:
image
Therefore, I retained the replace function.

),
"",
);
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/console_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[");
Expand Down