summaryrefslogtreecommitdiff
path: root/js/os.ts
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-08-15 23:36:48 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-08-21 15:37:45 -0400
commit18d495c7d17cf3fce3835e732094d058f51eddaa (patch)
treef7244cfd83dbff9d8aaf67203feb0f3a24fe95f3 /js/os.ts
parentcb1393cdaea4bfbee69efbf7ce86a4adfc4593b3 (diff)
Better error handling in src/handlers.rs
Introduces error codes that are shared between JS/RS Fixes #526.
Diffstat (limited to 'js/os.ts')
-rw-r--r--js/os.ts16
1 files changed, 4 insertions, 12 deletions
diff --git a/js/os.ts b/js/os.ts
index bd7754ea0..22ef6ef4f 100644
--- a/js/os.ts
+++ b/js/os.ts
@@ -3,6 +3,7 @@ import { ModuleInfo } from "./types";
import { deno as fbs } from "gen/msg_generated";
import { assert } from "./util";
import * as util from "./util";
+import { maybeThrowError } from "./errors";
import { flatbuffers } from "flatbuffers";
import { libdeno } from "./globals";
@@ -43,9 +44,7 @@ export function codeFetch(
// null assertion `!`
const bb = new flatbuffers.ByteBuffer(new Uint8Array(resBuf!));
const baseRes = fbs.Base.getRootAsBase(bb);
- if (fbs.Any.NONE === baseRes.msgType()) {
- throw Error(baseRes.error()!);
- }
+ maybeThrowError(baseRes);
assert(fbs.Any.CodeFetchRes === baseRes.msgType());
const codeFetchRes = new fbs.CodeFetchRes();
assert(baseRes.msg(codeFetchRes) != null);
@@ -82,10 +81,7 @@ export function codeCache(
if (resBuf != null) {
const bb = new flatbuffers.ByteBuffer(new Uint8Array(resBuf));
const baseRes = fbs.Base.getRootAsBase(bb);
- assert(fbs.Any.NONE === baseRes.msgType());
- // undefined and null are incompatible in strict mode, but at runtime
- // a null value is fine, therefore not null assertion
- throw Error(baseRes.error()!);
+ maybeThrowError(baseRes);
}
}
@@ -112,11 +108,7 @@ export function readFileSync(filename: string): Uint8Array {
// null assertion `!`
const bb = new flatbuffers.ByteBuffer(new Uint8Array(resBuf!));
const baseRes = fbs.Base.getRootAsBase(bb);
- if (fbs.Any.NONE === baseRes.msgType()) {
- // undefined and null are incompatible in strict mode, but at runtime
- // a null value is fine, therefore not null assertion
- throw Error(baseRes.error()!);
- }
+ maybeThrowError(baseRes);
assert(fbs.Any.ReadFileSyncRes === baseRes.msgType());
const res = new fbs.ReadFileSyncRes();
assert(baseRes.msg(res) != null);