diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-08-15 23:36:48 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-08-21 15:37:45 -0400 |
commit | 18d495c7d17cf3fce3835e732094d058f51eddaa (patch) | |
tree | f7244cfd83dbff9d8aaf67203feb0f3a24fe95f3 /js/os.ts | |
parent | cb1393cdaea4bfbee69efbf7ce86a4adfc4593b3 (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.ts | 16 |
1 files changed, 4 insertions, 12 deletions
@@ -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); |