Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(ext/console): Error Cause Not Inspect-Formatted when printed #24526

Merged
9 changes: 8 additions & 1 deletion ext/console/01_console.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const {
FunctionPrototypeBind,
FunctionPrototypeCall,
FunctionPrototypeToString,
JSONStringify,
MapPrototypeDelete,
MapPrototypeEntries,
MapPrototypeForEach,
Expand Down Expand Up @@ -1484,12 +1485,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(
JSONStringify(cause, null, 2),
doubleQuoteRegExp,
"",
)),
),
"",
);
Expand Down