diff --git a/ext/console/01_console.js b/ext/console/01_console.js index 761368b57b..9b5e6fe1a4 100644 --- a/ext/console/01_console.js +++ b/ext/console/01_console.js @@ -1287,6 +1287,7 @@ function getKeys(value, showHidden) { ArrayPrototypePushApply(keys, ArrayPrototypeFilter(symbols, filter)); } } + keys = ArrayPrototypeFilter(keys, (key) => key !== "cause"); return keys; } diff --git a/tests/unit/console_test.ts b/tests/unit/console_test.ts index 63ffff0dcb..201d18f004 100644 --- a/tests/unit/console_test.ts +++ b/tests/unit/console_test.ts @@ -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) => {