1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
// Warning! The values in this enum are duplicated in cli/msg.rs
// 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,
UnexpectedEof = 17,
BadResource = 18,
Http = 19,
URIError = 20,
TypeError = 21,
Other = 22
}
export function constructError(kind: ErrorKind, msg: string): never {
switch (kind) {
case ErrorKind.TypeError:
throw new TypeError(msg);
case ErrorKind.Other:
throw new Error(msg);
case ErrorKind.URIError:
throw new URIError(msg);
case ErrorKind.NotFound:
throw new NotFound(msg);
case ErrorKind.PermissionDenied:
throw new PermissionDenied(msg);
case ErrorKind.ConnectionRefused:
throw new ConnectionRefused(msg);
case ErrorKind.ConnectionReset:
throw new ConnectionReset(msg);
case ErrorKind.ConnectionAborted:
throw new ConnectionAborted(msg);
case ErrorKind.NotConnected:
throw new NotConnected(msg);
case ErrorKind.AddrInUse:
throw new AddrInUse(msg);
case ErrorKind.AddrNotAvailable:
throw new AddrNotAvailable(msg);
case ErrorKind.BrokenPipe:
throw new BrokenPipe(msg);
case ErrorKind.AlreadyExists:
throw new AlreadyExists(msg);
case ErrorKind.InvalidData:
throw new InvalidData(msg);
case ErrorKind.TimedOut:
throw new TimedOut(msg);
case ErrorKind.Interrupted:
throw new Interrupted(msg);
case ErrorKind.WriteZero:
throw new WriteZero(msg);
case ErrorKind.UnexpectedEof:
throw new UnexpectedEof(msg);
case ErrorKind.BadResource:
throw new BadResource(msg);
case ErrorKind.Http:
throw new Http(msg);
}
}
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";
}
}
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 Other extends Error {
constructor(msg: string) {
super(msg);
this.name = "Other";
}
}
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";
}
}
export const Err = {
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,
Other: Other,
UnexpectedEof: UnexpectedEof,
BadResource: BadResource,
Http: Http
};
|