mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 02:22:40 +00:00
Better error handling in src/handlers.rs
Introduces error codes that are shared between JS/RS Fixes #526.
This commit is contained in:
parent
cb1393cdae
commit
18d495c7d1
11 changed files with 304 additions and 127 deletions
16
js/os.ts
16
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue