diff --git a/js/deno.ts b/js/deno.ts index 0b6b0fb9b2..ba4a5151e6 100644 --- a/js/deno.ts +++ b/js/deno.ts @@ -13,5 +13,6 @@ export { lstatSync, writeFileSync } from "./os"; +export { ErrorKind, DenoError } from "./errors"; export { libdeno } from "./libdeno"; export const argv: string[] = []; diff --git a/js/errors.ts b/js/errors.ts index ad7b6be21f..d0254ef65f 100644 --- a/js/errors.ts +++ b/js/errors.ts @@ -1,10 +1,11 @@ import * as fbs from "gen/msg_generated"; +export { ErrorKind } from "gen/msg_generated"; // @internal export class DenoError extends Error { constructor(readonly kind: T, msg: string) { super(msg); - this.name = `deno.${fbs.ErrorKind[kind]}`; + this.name = fbs.ErrorKind[kind]; } } diff --git a/js/fetch_test.ts b/js/fetch_test.ts index 88cf834bc6..1af3bc2eb7 100644 --- a/js/fetch_test.ts +++ b/js/fetch_test.ts @@ -15,7 +15,6 @@ test(async function fetchPerm() { } catch (err_) { err = err_; } - // TODO assert(err instanceof deno.PermissionDenied). - assert(err); - assertEqual(err.name, "deno.PermissionDenied"); + assertEqual(err.kind, deno.ErrorKind.PermissionDenied); + assertEqual(err.name, "PermissionDenied"); }); diff --git a/js/os_test.ts b/js/os_test.ts index 3c1d926d85..7a252cb737 100644 --- a/js/os_test.ts +++ b/js/os_test.ts @@ -16,8 +16,8 @@ test(async function envFailure() { const env = deno.env(); } catch (err) { caughtError = true; - // TODO assert(err instanceof deno.PermissionDenied). - assertEqual(err.name, "deno.PermissionDenied"); + assertEqual(err.kind, deno.ErrorKind.PermissionDenied); + assertEqual(err.name, "PermissionDenied"); } assert(caughtError); @@ -47,9 +47,8 @@ test(async function statSyncNotFound() { badInfo = deno.statSync("bad_file_name"); } catch (err) { caughtError = true; - // TODO assert(err instanceof deno.NotFound). - assert(err); - assertEqual(err.name, "deno.NotFound"); + assertEqual(err.kind, deno.ErrorKind.NotFound); + assertEqual(err.name, "NotFound"); } assert(caughtError); @@ -78,9 +77,8 @@ test(async function lstatSyncNotFound() { badInfo = deno.lstatSync("bad_file_name"); } catch (err) { caughtError = true; - // TODO assert(err instanceof deno.NotFound). - assert(err); - assertEqual(err.name, "deno.NotFound"); + assertEqual(err.kind, deno.ErrorKind.NotFound); + assertEqual(err.name, "NotFound"); } assert(caughtError); @@ -138,8 +136,8 @@ testPerm({ write: true }, function writeFileSyncFail() { deno.writeFileSync(filename, data); } catch (e) { caughtError = true; - // TODO assertEqual(e, deno.NotFound); - assertEqual(e.name, "deno.NotFound"); + assertEqual(e.kind, deno.ErrorKind.NotFound); + assertEqual(e.name, "NotFound"); } assert(caughtError); }); @@ -166,9 +164,8 @@ testPerm({ write: true }, function makeTempDirSync() { } catch (err_) { err = err_; } - // TODO assert(err instanceof deno.NotFound). - assert(err); - assertEqual(err.name, "deno.NotFound"); + assertEqual(err.kind, deno.ErrorKind.NotFound); + assertEqual(err.name, "NotFound"); }); test(function makeTempDirSyncPerm() { @@ -179,9 +176,8 @@ test(function makeTempDirSyncPerm() { } catch (err_) { err = err_; } - // TODO assert(err instanceof deno.PermissionDenied). - assert(err); - assertEqual(err.name, "deno.PermissionDenied"); + assertEqual(err.kind, deno.ErrorKind.PermissionDenied); + assertEqual(err.name, "PermissionDenied"); }); testPerm({ write: true }, function mkdirSync() { @@ -199,9 +195,8 @@ testPerm({ write: false }, function mkdDirSyncPerm() { } catch (err_) { err = err_; } - // TODO assert(err instanceof deno.PermissionDenied). - assert(err); - assertEqual(err.name, "deno.PermissionDenied"); + assertEqual(err.kind, deno.ErrorKind.PermissionDenied); + assertEqual(err.name, "PermissionDenied"); }); testPerm({ write: true }, function renameSync() { @@ -220,9 +215,8 @@ testPerm({ write: true }, function renameSync() { oldPathInfo = deno.statSync(oldpath); } catch (err) { caughtErr = true; - // TODO assert(err instanceof deno.NotFound). - assert(err); - assertEqual(err.name, "deno.NotFound"); + assertEqual(err.kind, deno.ErrorKind.NotFound); + assertEqual(err.name, "NotFound"); } assert(caughtErr); @@ -238,7 +232,6 @@ test(function renameSyncPerm() { } catch (err_) { err = err_; } - // TODO assert(err instanceof deno.PermissionDenied). - assert(err); - assertEqual(err.name, "deno.PermissionDenied"); + assertEqual(err.kind, deno.ErrorKind.PermissionDenied); + assertEqual(err.name, "PermissionDenied"); });