mirror of
https://github.com/denoland/deno.git
synced 2024-12-21 23:04:45 -05:00
fix(ext/console): prevent duplicate error printing when the cause is assigned (#25327)
This commit fixes the error format when the cause is assigned separately, ensuring that the cause is only printed once instead of twice. The fix addresses issue [#21651](https://github.com/denoland/deno/issues/21651).
This commit is contained in:
parent
c9065103b8
commit
4983f763d4
2 changed files with 20 additions and 0 deletions
|
@ -1287,6 +1287,7 @@ function getKeys(value, showHidden) {
|
|||
ArrayPrototypePushApply(keys, ArrayPrototypeFilter(symbols, filter));
|
||||
}
|
||||
}
|
||||
keys = ArrayPrototypeFilter(keys, (key) => key !== "cause");
|
||||
return keys;
|
||||
}
|
||||
|
||||
|
|
|
@ -1894,6 +1894,25 @@ Deno.test(function consoleLogShouldNotThrowErrorWhenInputIsProxiedTypedArray() {
|
|||
});
|
||||
});
|
||||
|
||||
Deno.test(function consoleLogWhenCauseIsAssignedShouldNotPrintCauseTwice() {
|
||||
mockConsole((console, out) => {
|
||||
const typeError = new TypeError("Type incorrect");
|
||||
const syntaxError = new SyntaxError("Improper syntax");
|
||||
typeError.cause = syntaxError;
|
||||
console.log(typeError);
|
||||
const result = stripAnsiCode(out.toString());
|
||||
// Filter out stack trace lines, keeping only the first line and the cause line
|
||||
const filteredOutput = result
|
||||
.split("\n")
|
||||
.filter((line) => !line.trim().startsWith("at"))
|
||||
.join("\n");
|
||||
|
||||
const expectedResult =
|
||||
"TypeError: Type incorrect\nCaused by SyntaxError: Improper syntax\n";
|
||||
assertEquals(filteredOutput.trim(), expectedResult.trim());
|
||||
});
|
||||
});
|
||||
|
||||
// console.log(new Proxy(new RegExp(), {}))
|
||||
Deno.test(function consoleLogShouldNotThrowErrorWhenInputIsProxiedRegExp() {
|
||||
mockConsole((console, out) => {
|
||||
|
|
Loading…
Reference in a new issue