Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix console.log when error has been caught #2041

Merged
merged 2 commits into from Apr 3, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -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) {
@@ -254,7 +254,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")
);
}
@@ -583,3 +583,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);
});
});
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.