diff options
author | Nayeem Rahman <muhammed.9939@gmail.com> | 2020-02-29 18:04:10 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-29 19:04:10 +0100 |
commit | 1f9d158bdc212e8cb15b92039c9cd11884c9708c (patch) | |
tree | 4c89fc3bb84c793f18ba8c5509ebf4dd1f6781ba /cli/js/errors.ts | |
parent | f55b22e195ff0dfaf117aaef2a0fcc51fe0058c8 (diff) |
refactor(cli/js): Replace constructError() with getErrorClass() (#4189)
Flattens dispatch error handling to produce one less useless stack frame on op errors.
Diffstat (limited to 'cli/js/errors.ts')
-rw-r--r-- | cli/js/errors.ts | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/cli/js/errors.ts b/cli/js/errors.ts index 0379f3c96..44f35b438 100644 --- a/cli/js/errors.ts +++ b/cli/js/errors.ts @@ -25,48 +25,48 @@ export enum ErrorKind { Other = 22 } -export function constructError(kind: ErrorKind, msg: string): never { +export function getErrorClass(kind: ErrorKind): { new (msg: string): Error } { switch (kind) { case ErrorKind.TypeError: - throw new TypeError(msg); + return TypeError; case ErrorKind.Other: - throw new Error(msg); + return Error; case ErrorKind.URIError: - throw new URIError(msg); + return URIError; case ErrorKind.NotFound: - throw new NotFound(msg); + return NotFound; case ErrorKind.PermissionDenied: - throw new PermissionDenied(msg); + return PermissionDenied; case ErrorKind.ConnectionRefused: - throw new ConnectionRefused(msg); + return ConnectionRefused; case ErrorKind.ConnectionReset: - throw new ConnectionReset(msg); + return ConnectionReset; case ErrorKind.ConnectionAborted: - throw new ConnectionAborted(msg); + return ConnectionAborted; case ErrorKind.NotConnected: - throw new NotConnected(msg); + return NotConnected; case ErrorKind.AddrInUse: - throw new AddrInUse(msg); + return AddrInUse; case ErrorKind.AddrNotAvailable: - throw new AddrNotAvailable(msg); + return AddrNotAvailable; case ErrorKind.BrokenPipe: - throw new BrokenPipe(msg); + return BrokenPipe; case ErrorKind.AlreadyExists: - throw new AlreadyExists(msg); + return AlreadyExists; case ErrorKind.InvalidData: - throw new InvalidData(msg); + return InvalidData; case ErrorKind.TimedOut: - throw new TimedOut(msg); + return TimedOut; case ErrorKind.Interrupted: - throw new Interrupted(msg); + return Interrupted; case ErrorKind.WriteZero: - throw new WriteZero(msg); + return WriteZero; case ErrorKind.UnexpectedEof: - throw new UnexpectedEof(msg); + return UnexpectedEof; case ErrorKind.BadResource: - throw new BadResource(msg); + return BadResource; case ErrorKind.Http: - throw new Http(msg); + return Http; } } |