2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2018-08-15 23:36:48 -04:00
|
|
|
|
2020-02-24 15:48:35 -05:00
|
|
|
// Warning! The values in this enum are duplicated in cli/op_error.rs
|
2019-08-26 17:02:34 -04:00
|
|
|
// Update carefully!
|
|
|
|
export enum ErrorKind {
|
|
|
|
NotFound = 1,
|
|
|
|
PermissionDenied = 2,
|
|
|
|
ConnectionRefused = 3,
|
|
|
|
ConnectionReset = 4,
|
|
|
|
ConnectionAborted = 5,
|
|
|
|
NotConnected = 6,
|
|
|
|
AddrInUse = 7,
|
|
|
|
AddrNotAvailable = 8,
|
|
|
|
BrokenPipe = 9,
|
|
|
|
AlreadyExists = 10,
|
|
|
|
InvalidData = 13,
|
|
|
|
TimedOut = 14,
|
|
|
|
Interrupted = 15,
|
|
|
|
WriteZero = 16,
|
2020-02-21 10:36:13 -05:00
|
|
|
UnexpectedEof = 17,
|
|
|
|
BadResource = 18,
|
|
|
|
Http = 19,
|
|
|
|
URIError = 20,
|
|
|
|
TypeError = 21,
|
2020-03-28 13:03:49 -04:00
|
|
|
Other = 22,
|
2020-02-21 10:36:13 -05:00
|
|
|
}
|
|
|
|
|
2020-02-29 13:04:10 -05:00
|
|
|
export function getErrorClass(kind: ErrorKind): { new (msg: string): Error } {
|
2020-02-21 10:36:13 -05:00
|
|
|
switch (kind) {
|
|
|
|
case ErrorKind.TypeError:
|
2020-02-29 13:04:10 -05:00
|
|
|
return TypeError;
|
2020-02-21 10:36:13 -05:00
|
|
|
case ErrorKind.Other:
|
2020-02-29 13:04:10 -05:00
|
|
|
return Error;
|
2020-02-21 10:36:13 -05:00
|
|
|
case ErrorKind.URIError:
|
2020-02-29 13:04:10 -05:00
|
|
|
return URIError;
|
2020-02-21 10:36:13 -05:00
|
|
|
case ErrorKind.NotFound:
|
2020-02-29 13:04:10 -05:00
|
|
|
return NotFound;
|
2020-02-21 10:36:13 -05:00
|
|
|
case ErrorKind.PermissionDenied:
|
2020-02-29 13:04:10 -05:00
|
|
|
return PermissionDenied;
|
2020-02-21 10:36:13 -05:00
|
|
|
case ErrorKind.ConnectionRefused:
|
2020-02-29 13:04:10 -05:00
|
|
|
return ConnectionRefused;
|
2020-02-21 10:36:13 -05:00
|
|
|
case ErrorKind.ConnectionReset:
|
2020-02-29 13:04:10 -05:00
|
|
|
return ConnectionReset;
|
2020-02-21 10:36:13 -05:00
|
|
|
case ErrorKind.ConnectionAborted:
|
2020-02-29 13:04:10 -05:00
|
|
|
return ConnectionAborted;
|
2020-02-21 10:36:13 -05:00
|
|
|
case ErrorKind.NotConnected:
|
2020-02-29 13:04:10 -05:00
|
|
|
return NotConnected;
|
2020-02-21 10:36:13 -05:00
|
|
|
case ErrorKind.AddrInUse:
|
2020-02-29 13:04:10 -05:00
|
|
|
return AddrInUse;
|
2020-02-21 10:36:13 -05:00
|
|
|
case ErrorKind.AddrNotAvailable:
|
2020-02-29 13:04:10 -05:00
|
|
|
return AddrNotAvailable;
|
2020-02-21 10:36:13 -05:00
|
|
|
case ErrorKind.BrokenPipe:
|
2020-02-29 13:04:10 -05:00
|
|
|
return BrokenPipe;
|
2020-02-21 10:36:13 -05:00
|
|
|
case ErrorKind.AlreadyExists:
|
2020-02-29 13:04:10 -05:00
|
|
|
return AlreadyExists;
|
2020-02-21 10:36:13 -05:00
|
|
|
case ErrorKind.InvalidData:
|
2020-02-29 13:04:10 -05:00
|
|
|
return InvalidData;
|
2020-02-21 10:36:13 -05:00
|
|
|
case ErrorKind.TimedOut:
|
2020-02-29 13:04:10 -05:00
|
|
|
return TimedOut;
|
2020-02-21 10:36:13 -05:00
|
|
|
case ErrorKind.Interrupted:
|
2020-02-29 13:04:10 -05:00
|
|
|
return Interrupted;
|
2020-02-21 10:36:13 -05:00
|
|
|
case ErrorKind.WriteZero:
|
2020-02-29 13:04:10 -05:00
|
|
|
return WriteZero;
|
2020-02-21 10:36:13 -05:00
|
|
|
case ErrorKind.UnexpectedEof:
|
2020-02-29 13:04:10 -05:00
|
|
|
return UnexpectedEof;
|
2020-02-21 10:36:13 -05:00
|
|
|
case ErrorKind.BadResource:
|
2020-02-29 13:04:10 -05:00
|
|
|
return BadResource;
|
2020-02-21 10:36:13 -05:00
|
|
|
case ErrorKind.Http:
|
2020-02-29 13:04:10 -05:00
|
|
|
return Http;
|
2020-02-21 10:36:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class NotFound extends Error {
|
|
|
|
constructor(msg: string) {
|
|
|
|
super(msg);
|
|
|
|
this.name = "NotFound";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class PermissionDenied extends Error {
|
|
|
|
constructor(msg: string) {
|
|
|
|
super(msg);
|
|
|
|
this.name = "PermissionDenied";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class ConnectionRefused extends Error {
|
|
|
|
constructor(msg: string) {
|
|
|
|
super(msg);
|
|
|
|
this.name = "ConnectionRefused";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class ConnectionReset extends Error {
|
|
|
|
constructor(msg: string) {
|
|
|
|
super(msg);
|
|
|
|
this.name = "ConnectionReset";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class ConnectionAborted extends Error {
|
|
|
|
constructor(msg: string) {
|
|
|
|
super(msg);
|
|
|
|
this.name = "ConnectionAborted";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class NotConnected extends Error {
|
|
|
|
constructor(msg: string) {
|
|
|
|
super(msg);
|
|
|
|
this.name = "NotConnected";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class AddrInUse extends Error {
|
|
|
|
constructor(msg: string) {
|
|
|
|
super(msg);
|
|
|
|
this.name = "AddrInUse";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class AddrNotAvailable extends Error {
|
|
|
|
constructor(msg: string) {
|
|
|
|
super(msg);
|
|
|
|
this.name = "AddrNotAvailable";
|
|
|
|
}
|
2019-08-26 17:02:34 -04:00
|
|
|
}
|
2020-02-21 10:36:13 -05:00
|
|
|
class BrokenPipe extends Error {
|
|
|
|
constructor(msg: string) {
|
|
|
|
super(msg);
|
|
|
|
this.name = "BrokenPipe";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class AlreadyExists extends Error {
|
|
|
|
constructor(msg: string) {
|
|
|
|
super(msg);
|
|
|
|
this.name = "AlreadyExists";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class InvalidData extends Error {
|
|
|
|
constructor(msg: string) {
|
|
|
|
super(msg);
|
|
|
|
this.name = "InvalidData";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class TimedOut extends Error {
|
|
|
|
constructor(msg: string) {
|
|
|
|
super(msg);
|
|
|
|
this.name = "TimedOut";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class Interrupted extends Error {
|
|
|
|
constructor(msg: string) {
|
|
|
|
super(msg);
|
|
|
|
this.name = "Interrupted";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class WriteZero extends Error {
|
|
|
|
constructor(msg: string) {
|
|
|
|
super(msg);
|
|
|
|
this.name = "WriteZero";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class UnexpectedEof extends Error {
|
|
|
|
constructor(msg: string) {
|
|
|
|
super(msg);
|
|
|
|
this.name = "UnexpectedEof";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class BadResource extends Error {
|
|
|
|
constructor(msg: string) {
|
|
|
|
super(msg);
|
|
|
|
this.name = "BadResource";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class Http extends Error {
|
|
|
|
constructor(msg: string) {
|
|
|
|
super(msg);
|
|
|
|
this.name = "Http";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-24 15:48:35 -05:00
|
|
|
export const errors = {
|
2020-02-21 10:36:13 -05:00
|
|
|
NotFound: NotFound,
|
|
|
|
PermissionDenied: PermissionDenied,
|
|
|
|
ConnectionRefused: ConnectionRefused,
|
|
|
|
ConnectionReset: ConnectionReset,
|
|
|
|
ConnectionAborted: ConnectionAborted,
|
|
|
|
NotConnected: NotConnected,
|
|
|
|
AddrInUse: AddrInUse,
|
|
|
|
AddrNotAvailable: AddrNotAvailable,
|
|
|
|
BrokenPipe: BrokenPipe,
|
|
|
|
AlreadyExists: AlreadyExists,
|
|
|
|
InvalidData: InvalidData,
|
|
|
|
TimedOut: TimedOut,
|
|
|
|
Interrupted: Interrupted,
|
|
|
|
WriteZero: WriteZero,
|
|
|
|
UnexpectedEof: UnexpectedEof,
|
|
|
|
BadResource: BadResource,
|
2020-03-28 13:03:49 -04:00
|
|
|
Http: Http,
|
2020-02-21 10:36:13 -05:00
|
|
|
};
|