mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
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>
This commit is contained in:
parent
4e8f5875bc
commit
994b6327d3
2 changed files with 23 additions and 1 deletions
|
@ -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,
|
||||
"",
|
||||
)),
|
||||
),
|
||||
"",
|
||||
);
|
||||
|
|
|
@ -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[");
|
||||
|
|
Loading…
Reference in a new issue