diff options
author | 迷渡 <justjavac@gmail.com> | 2019-04-03 20:38:50 +0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-04-03 08:38:50 -0400 |
commit | 5f97c041d9115c480e3b9f428cfee27b109b3883 (patch) | |
tree | 4e6c6f6df6f61c81cddbf9201b40a24e21e848b5 /js | |
parent | 6463a75b44a4f7aad6ffe04d0c5ae073fb5ca137 (diff) |
fix console.log when error has been caught (#2041)
Diffstat (limited to 'js')
-rw-r--r-- | js/console.ts | 5 | ||||
-rw-r--r-- | js/console_test.ts | 20 |
2 files changed, 20 insertions, 5 deletions
diff --git a/js/console.ts b/js/console.ts index 3669a1d3b..ec7238cb9 100644 --- a/js/console.ts +++ b/js/console.ts @@ -4,8 +4,6 @@ import { TypedArray } from "./types"; import { TextEncoder } from "./text_encoding"; import { File, stdout } from "./files"; import { cliTable } from "./console_table"; -import { formatError } from "./format_error"; -import { core } from "./core"; type ConsoleContext = Set<unknown>; type ConsoleOptions = Partial<{ @@ -323,8 +321,7 @@ function createObjectString( ...args: [ConsoleContext, number, number] ): string { if (value instanceof Error) { - const errorJSON = core.errorToJSON(value); - return formatError(errorJSON); + return String(value.stack); } else if (Array.isArray(value)) { return createArrayString(value, ...args); } else if (value instanceof Number) { diff --git a/js/console_test.ts b/js/console_test.ts index ed2f37548..7bedcf973 100644 --- a/js/console_test.ts +++ b/js/console_test.ts @@ -264,7 +264,7 @@ test(function consoleTestError() { } catch (e) { assert( stringify(e) - .split("\n")[3] + .split("\n")[0] // error has been caught .includes("MyError: This is an error") ); } @@ -593,3 +593,21 @@ test(function consoleTable() { assertEquals(out.toString(), "test\n"); }); }); + +// console.log(Error) test +test(function consoleLogShouldNotThrowError() { + let result = 0; + try { + console.log(new Error("foo")); + result = 1; + } catch (e) { + result = 2; + } + assertEquals(result, 1); + + // output errors to the console should not include "Uncaught" + mockConsole((console, out) => { + console.log(new Error("foo")); + assertEquals(out.toString().includes("Uncaught"), false); + }); +}); |