diff options
author | Bert Belder <bertbelder@gmail.com> | 2020-03-02 14:20:16 -0800 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2020-03-02 14:20:16 -0800 |
commit | eafd40feabaf14f9f88748c66fa319519fd69072 (patch) | |
tree | ccb3a5848fec4bc013aad774fc9c9bda2f894043 /cli/js | |
parent | 3fcbf8789e7f873f8a562b200ab82ea7cec173d8 (diff) |
Do not convert exceptions to JSON and back (#4214)
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/format_error.ts | 6 | ||||
-rw-r--r-- | cli/js/globals.ts | 2 | ||||
-rw-r--r-- | cli/js/repl.ts | 9 |
3 files changed, 4 insertions, 13 deletions
diff --git a/cli/js/format_error.ts b/cli/js/format_error.ts index 21c4bcfa8..0a322338a 100644 --- a/cli/js/format_error.ts +++ b/cli/js/format_error.ts @@ -2,12 +2,6 @@ import { DiagnosticItem } from "./diagnostics.ts"; import { sendSync } from "./dispatch_json.ts"; -// TODO(bartlomieju): move to `repl.ts`? -export function formatError(errString: string): string { - const res = sendSync("op_format_error", { error: errString }); - return res.error; -} - /** * Format an array of diagnostic items and return them as a single string. * @param items An array of diagnostic items to format diff --git a/cli/js/globals.ts b/cli/js/globals.ts index 9a7161ff0..fd2082e40 100644 --- a/cli/js/globals.ts +++ b/cli/js/globals.ts @@ -96,7 +96,7 @@ declare global { // eslint-disable-next-line @typescript-eslint/no-explicit-any evalContext(code: string): [any, EvalErrorInfo | null]; - errorToJSON: (e: Error) => string; + formatError: (e: Error) => string; } // Only `var` variables show up in the `globalThis` type when doing a global diff --git a/cli/js/repl.ts b/cli/js/repl.ts index 6e4f2545a..0ef86ecd9 100644 --- a/cli/js/repl.ts +++ b/cli/js/repl.ts @@ -2,7 +2,6 @@ import { close } from "./files.ts"; import { exit } from "./os.ts"; import { core } from "./core.ts"; -import { formatError } from "./format_error.ts"; import { stringifyArgs } from "./console.ts"; import { sendSync, sendAsync } from "./dispatch_json.ts"; @@ -89,9 +88,7 @@ function evaluate(code: string): boolean { } else { lastThrownError = errInfo.thrown; if (errInfo.isNativeError) { - const formattedError = formatError( - core.errorToJSON(errInfo.thrown as Error) - ); + const formattedError = core.formatError(errInfo.thrown as Error); replError(formattedError); } else { replError("Thrown:", errInfo.thrown); @@ -162,7 +159,7 @@ export async function replLoop(): Promise<void> { if (err.message !== "Interrupted") { // e.g. this happens when we have deno.close(3). // We want to display the problem. - const formattedError = formatError(core.errorToJSON(err)); + const formattedError = core.formatError(err); replError(formattedError); } // Quit REPL anyways. @@ -184,7 +181,7 @@ export async function replLoop(): Promise<void> { } else { // e.g. this happens when we have deno.close(3). // We want to display the problem. - const formattedError = formatError(core.errorToJSON(err)); + const formattedError = core.formatError(err); replError(formattedError); quitRepl(1); } |