diff options
author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2019-02-09 13:55:40 -0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-02-09 16:55:40 -0500 |
commit | 1d36eb47eb882cb9305a6338019fa2a2b375d7b1 (patch) | |
tree | 4584aff9da784f3e05c4fb5314d5911772b4d655 /js/format_error.ts | |
parent | 1502051453bf16787a59f43004b24d553d39bd26 (diff) |
Support scoped variables, unblock REPL async op, and REPL error colors (#1721)
Diffstat (limited to 'js/format_error.ts')
-rw-r--r-- | js/format_error.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/js/format_error.ts b/js/format_error.ts new file mode 100644 index 000000000..ebc579355 --- /dev/null +++ b/js/format_error.ts @@ -0,0 +1,21 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +import * as msg from "gen/msg_generated"; +import * as flatbuffers from "./flatbuffers"; +import { sendSync } from "./dispatch"; +import { assert } from "./util"; + +export function formatError(errString: string): string { + const builder = flatbuffers.createBuilder(); + const errString_ = builder.createString(errString); + msg.FormatError.startFormatError(builder); + msg.FormatError.addError(builder, errString_); + const offset = msg.FormatError.endFormatError(builder); + const baseRes = sendSync(builder, msg.Any.FormatError, offset); + assert(baseRes != null); + assert(msg.Any.FormatErrorRes === baseRes!.innerType()); + const formatErrorResMsg = new msg.FormatErrorRes(); + assert(baseRes!.inner(formatErrorResMsg) != null); + const formattedError = formatErrorResMsg.error(); + assert(formatError != null); + return formattedError!; +} |