summaryrefslogtreecommitdiff
path: root/js/errors.ts
blob: 11d4cd509ab667f435d5d9953953f5578804ef43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { deno as fbs } from "gen/msg_generated";

// @internal
export class DenoError<T extends fbs.ErrorKind> extends Error {
  constructor(readonly kind: T, msg: string) {
    super(msg);
    this.name = `deno.${fbs.ErrorKind[kind]}`;
  }
}

// @internal
export function maybeThrowError(base: fbs.Base): void {
  const kind = base.errorKind();
  if (kind !== fbs.ErrorKind.NoError) {
    throw new DenoError(kind, base.error()!);
  }
}