mirror of
https://github.com/denoland/deno
synced 2024-08-27 20:09:17 +00:00
fix console.log when error has been caught (#2041)
This commit is contained in:
parent
6463a75b44
commit
5f97c041d9
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue