blob: 72fc5f23b4679e2d1137a9bde2a412b6d73d3341 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import * as msg from "gen/msg_generated";
export { ErrorKind } from "gen/msg_generated";
// @internal
export class DenoError<T extends msg.ErrorKind> extends Error {
constructor(readonly kind: T, errStr: string) {
super(errStr);
this.name = msg.ErrorKind[kind];
}
}
// @internal
export function maybeThrowError(base: msg.Base): void {
const err = maybeError(base);
if (err != null) {
throw err;
}
}
export function maybeError(base: msg.Base): null | DenoError<msg.ErrorKind> {
const kind = base.errorKind();
if (kind === msg.ErrorKind.NoError) {
return null;
} else {
return new DenoError(kind, base.error()!);
}
}
|