diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-01-20 16:50:16 +0100 |
---|---|---|
committer | Ry Dahl <ry@tinyclouds.org> | 2020-01-20 10:50:16 -0500 |
commit | c90036ab88bb1ae6b9c87d5e368f56d8c8afab69 (patch) | |
tree | ebc7b762151489440135c029a1217c80bb810900 /cli/js | |
parent | e83658138bff3605bd37c2b4ae4703081d884729 (diff) |
refactor: reduce number of ErrorKind variants (#3662)
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/errors.ts | 49 | ||||
-rw-r--r-- | cli/js/fetch_test.ts | 8 | ||||
-rw-r--r-- | cli/js/lib.deno_runtime.d.ts | 45 | ||||
-rw-r--r-- | cli/js/permissions_test.ts | 5 | ||||
-rw-r--r-- | cli/js/streams/shared-internals.ts | 6 |
5 files changed, 29 insertions, 84 deletions
diff --git a/cli/js/errors.ts b/cli/js/errors.ts index f8210fb60..0f75453ce 100644 --- a/cli/js/errors.ts +++ b/cli/js/errors.ts @@ -8,9 +8,9 @@ * } catch (e) { * if ( * e instanceof Deno.DenoError && - * e.kind === Deno.ErrorKind.Overflow + * e.kind === Deno.ErrorKind.NotFound * ) { - * console.error("Overflow error!"); + * console.error("NotFound error!"); * } * } * @@ -25,7 +25,6 @@ export class DenoError<T extends ErrorKind> extends Error { // Warning! The values in this enum are duplicated in cli/msg.rs // Update carefully! export enum ErrorKind { - NoError = 0, NotFound = 1, PermissionDenied = 2, ConnectionRefused = 3, @@ -45,39 +44,13 @@ export enum ErrorKind { Other = 17, UnexpectedEof = 18, BadResource = 19, - CommandFailed = 20, - EmptyHost = 21, - IdnaError = 22, - InvalidPort = 23, - InvalidIpv4Address = 24, - InvalidIpv6Address = 25, - InvalidDomainCharacter = 26, - RelativeUrlWithoutBase = 27, - RelativeUrlWithCannotBeABaseBase = 28, - SetHostOnCannotBeABaseUrl = 29, - Overflow = 30, - HttpUser = 31, - HttpClosed = 32, - HttpCanceled = 33, - HttpParse = 34, - HttpOther = 35, - TooLarge = 36, - InvalidUri = 37, - InvalidSeekMode = 38, - OpNotAvailable = 39, - WorkerInitFailed = 40, - UnixError = 41, - NoAsyncSupport = 42, - NoSyncSupport = 43, - ImportMapError = 44, - InvalidPath = 45, - ImportPrefixMissing = 46, - UnsupportedFetchScheme = 47, - TooManyRedirects = 48, - Diagnostic = 49, - JSError = 50, - TypeError = 51, - - /** TODO this is a DomException type, and should be moved out of here when possible */ - DataCloneError = 52 + UrlParse = 20, + Http = 21, + TooLarge = 22, + InvalidSeekMode = 23, + UnixError = 24, + InvalidPath = 25, + ImportPrefixMissing = 26, + Diagnostic = 27, + JSError = 28 } diff --git a/cli/js/fetch_test.ts b/cli/js/fetch_test.ts index 97d6fd717..92d1176cc 100644 --- a/cli/js/fetch_test.ts +++ b/cli/js/fetch_test.ts @@ -15,8 +15,8 @@ testPerm({ net: true }, async function fetchConnectionError(): Promise<void> { } catch (err_) { err = err_; } - assertEquals(err.kind, Deno.ErrorKind.HttpOther); - assertEquals(err.name, "HttpOther"); + assertEquals(err.kind, Deno.ErrorKind.Http); + assertEquals(err.name, "Http"); assertStrContains(err.message, "error trying to connect"); }); @@ -106,8 +106,8 @@ testPerm({ net: true }, async function fetchEmptyInvalid(): Promise<void> { } catch (err_) { err = err_; } - assertEquals(err.kind, Deno.ErrorKind.RelativeUrlWithoutBase); - assertEquals(err.name, "RelativeUrlWithoutBase"); + assertEquals(err.kind, Deno.ErrorKind.UrlParse); + assertEquals(err.name, "UrlParse"); }); testPerm({ net: true }, async function fetchMultipartFormDataSuccess(): Promise< diff --git a/cli/js/lib.deno_runtime.d.ts b/cli/js/lib.deno_runtime.d.ts index 95c22305b..0fa183348 100644 --- a/cli/js/lib.deno_runtime.d.ts +++ b/cli/js/lib.deno_runtime.d.ts @@ -1114,9 +1114,9 @@ declare namespace Deno { * } catch (e) { * if ( * e instanceof Deno.DenoError && - * e.kind === Deno.ErrorKind.Overflow + * e.kind === Deno.ErrorKind.NotFound * ) { - * console.error("Overflow error!"); + * console.error("NotFound error!"); * } * } * @@ -1126,7 +1126,6 @@ declare namespace Deno { constructor(kind: T, msg: string); } export enum ErrorKind { - NoError = 0, NotFound = 1, PermissionDenied = 2, ConnectionRefused = 3, @@ -1146,37 +1145,15 @@ declare namespace Deno { Other = 17, UnexpectedEof = 18, BadResource = 19, - CommandFailed = 20, - EmptyHost = 21, - IdnaError = 22, - InvalidPort = 23, - InvalidIpv4Address = 24, - InvalidIpv6Address = 25, - InvalidDomainCharacter = 26, - RelativeUrlWithoutBase = 27, - RelativeUrlWithCannotBeABaseBase = 28, - SetHostOnCannotBeABaseUrl = 29, - Overflow = 30, - HttpUser = 31, - HttpClosed = 32, - HttpCanceled = 33, - HttpParse = 34, - HttpOther = 35, - TooLarge = 36, - InvalidUri = 37, - InvalidSeekMode = 38, - OpNotAvailable = 39, - WorkerInitFailed = 40, - UnixError = 41, - NoAsyncSupport = 42, - NoSyncSupport = 43, - ImportMapError = 44, - InvalidPath = 45, - ImportPrefixMissing = 46, - UnsupportedFetchScheme = 47, - TooManyRedirects = 48, - Diagnostic = 49, - JSError = 50 + UrlParse = 20, + Http = 21, + TooLarge = 22, + InvalidSeekMode = 23, + UnixError = 24, + InvalidPath = 25, + ImportPrefixMissing = 26, + Diagnostic = 27, + JSError = 28 } /** UNSTABLE: potentially want names to overlap more with browser. diff --git a/cli/js/permissions_test.ts b/cli/js/permissions_test.ts index 22e8494e9..d63dddb15 100644 --- a/cli/js/permissions_test.ts +++ b/cli/js/permissions_test.ts @@ -35,15 +35,14 @@ test(async function permissionInvalidName(): Promise<void> { // eslint-disable-next-line @typescript-eslint/no-explicit-any await Deno.permissions.query({ name: "foo" as any }); } catch (e) { - assert(e.name === "TypeError"); + assert(e.name === "Other"); } }); test(async function permissionNetInvalidUrl(): Promise<void> { try { - // Invalid url causes TypeError. await Deno.permissions.query({ name: "net", url: ":" }); } catch (e) { - assert(e.name === "TypeError"); + assert(e.name === "UrlParse"); } }); diff --git a/cli/js/streams/shared-internals.ts b/cli/js/streams/shared-internals.ts index 90e66e591..93155fecc 100644 --- a/cli/js/streams/shared-internals.ts +++ b/cli/js/streams/shared-internals.ts @@ -12,7 +12,6 @@ // TODO don't disable this warning import { AbortSignal, QueuingStrategySizeCallback } from "../dom_types.ts"; -import { DenoError, ErrorKind } from "../errors.ts"; // common stream fields @@ -208,10 +207,7 @@ export function cloneValue(value: any): any { default: // TODO this should be a DOMException, // https://github.com/stardazed/sd-streams/blob/master/packages/streams/src/shared-internals.ts#L171 - throw new DenoError( - ErrorKind.DataCloneError, - "Uncloneable value in stream" - ); + throw new Error("Uncloneable value in stream"); } } |