4
4
* AbortSignal.
5
5
*/
6
6
export class AbortError extends Error {
7
+ static name = 'AbortError'
8
+
7
9
constructor ( message : string = 'The operation was aborted' ) {
8
10
super ( message )
9
11
this . name = 'AbortError'
10
12
}
11
13
}
12
14
13
15
/**
14
- * @deprecated
16
+ * Thrown when a remote Peer ID does not match the expected one
15
17
*/
16
- export class CodeError < T extends Record < string , any > = Record < string , never > > extends Error {
17
- public readonly props : T
18
-
19
- constructor (
20
- message : string ,
21
- public readonly code : string ,
22
- props ?: T
23
- ) {
24
- super ( message )
25
-
26
- this . name = props ?. name ?? 'CodeError'
27
- this . props = props ?? { } as T // eslint-disable-line @typescript-eslint/consistent-type-assertions
28
- }
29
- }
30
-
31
- /**
32
- * @deprecated
33
- */
34
- export class AggregateCodeError < T extends Record < string , any > = Record < string , never > > extends AggregateError {
35
- public readonly props : T
36
-
37
- constructor (
38
- errors : Error [ ] ,
39
- message : string ,
40
- public readonly code : string ,
41
- props ?: T
42
- ) {
43
- super ( errors , message )
44
-
45
- this . name = props ?. name ?? 'AggregateCodeError'
46
- this . props = props ?? { } as T // eslint-disable-line @typescript-eslint/consistent-type-assertions
47
- }
48
- }
49
-
50
18
export class UnexpectedPeerError extends Error {
19
+ static name = 'UnexpectedPeerError'
20
+
51
21
constructor ( message = 'Unexpected Peer' ) {
52
22
super ( message )
53
23
this . name = 'UnexpectedPeerError'
54
24
}
55
25
}
56
26
27
+ /**
28
+ * Thrown when a crypto exchange fails
29
+ */
57
30
export class InvalidCryptoExchangeError extends Error {
31
+ static name = 'InvalidCryptoExchangeError'
32
+
58
33
constructor ( message = 'Invalid crypto exchange' ) {
59
34
super ( message )
60
35
this . name = 'InvalidCryptoExchangeError'
61
36
}
62
37
}
63
38
39
+ /**
40
+ * Thrown when invalid parameters are passed to a function or method call
41
+ */
64
42
export class InvalidParametersError extends Error {
43
+ static name = 'InvalidParametersError'
44
+
65
45
constructor ( message = 'Invalid parameters' ) {
66
46
super ( message )
67
47
this . name = 'InvalidParametersError'
68
48
}
69
49
}
70
50
51
+ /**
52
+ * Thrown when a public key is invalid
53
+ */
71
54
export class InvalidPublicKeyError extends Error {
55
+ static name = 'InvalidPublicKeyError'
56
+
72
57
constructor ( message = 'Invalid public key' ) {
73
58
super ( message )
74
59
this . name = 'InvalidPublicKeyError'
75
60
}
76
61
}
77
62
63
+ /**
64
+ * Thrown when a private key is invalid
65
+ */
78
66
export class InvalidPrivateKeyError extends Error {
67
+ static name = 'InvalidPrivateKeyError'
68
+
79
69
constructor ( message = 'Invalid private key' ) {
80
70
super ( message )
81
71
this . name = 'InvalidPrivateKeyError'
82
72
}
83
73
}
84
74
75
+ /**
76
+ * Thrown when a operation is unsupported
77
+ */
85
78
export class UnsupportedOperationError extends Error {
79
+ static name = 'UnsupportedOperationError'
80
+
86
81
constructor ( message = 'Unsupported operation' ) {
87
82
super ( message )
88
83
this . name = 'UnsupportedOperationError'
89
84
}
90
85
}
91
86
87
+ /**
88
+ * Thrown when a connection is closing
89
+ */
92
90
export class ConnectionClosingError extends Error {
91
+ static name = 'ConnectionClosingError'
92
+
93
93
constructor ( message = 'The connection is closing' ) {
94
94
super ( message )
95
95
this . name = 'ConnectionClosingError'
96
96
}
97
97
}
98
98
99
+ /**
100
+ * Thrown when a connection is closed
101
+ */
99
102
export class ConnectionClosedError extends Error {
103
+ static name = 'ConnectionClosedError'
104
+
100
105
constructor ( message = 'The connection is closed' ) {
101
106
super ( message )
102
107
this . name = 'ConnectionClosedError'
103
108
}
104
109
}
105
110
111
+ /**
112
+ * Thrown when a connection fails
113
+ */
106
114
export class ConnectionFailedError extends Error {
115
+ static name = 'ConnectionFailedError'
116
+
107
117
constructor ( message = 'Connection failed' ) {
108
118
super ( message )
109
119
this . name = 'ConnectionFailedError'
110
120
}
111
121
}
112
122
123
+ /**
124
+ * Thrown when the muxer is closed and an attempt to open a stream occurs
125
+ */
126
+ export class MuxerClosedError extends Error {
127
+ static name = 'MuxerClosedError'
128
+
129
+ constructor ( message = 'The muxer is closed' ) {
130
+ super ( message )
131
+ this . name = 'MuxerClosedError'
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Thrown when a protocol stream is reset by the remote muxer
137
+ */
113
138
export class StreamResetError extends Error {
139
+ static name = 'StreamResetError'
140
+
114
141
constructor ( message = 'The stream has been reset' ) {
115
142
super ( message )
116
143
this . name = 'StreamResetError'
117
144
}
118
145
}
119
146
147
+ /**
148
+ * Thrown when a stream is in an invalid state
149
+ */
120
150
export class StreamStateError extends Error {
151
+ static name = 'StreamStateError'
152
+
121
153
constructor ( message = 'The stream is in an invalid state' ) {
122
154
super ( message )
123
155
this . name = 'StreamStateError'
124
156
}
125
157
}
126
158
159
+ /**
160
+ * Thrown when a value could not be found
161
+ */
127
162
export class NotFoundError extends Error {
163
+ static name = 'NotFoundError'
164
+
128
165
constructor ( message = 'Not found' ) {
129
166
super ( message )
130
167
this . name = 'NotFoundError'
131
168
}
132
169
}
133
170
171
+ /**
172
+ * Thrown when an invalid peer ID is encountered
173
+ */
134
174
export class InvalidPeerIdError extends Error {
175
+ static name = 'InvalidPeerIdError'
176
+
135
177
constructor ( message = 'Invalid PeerID' ) {
136
178
super ( message )
137
179
this . name = 'InvalidPeerIdError'
138
180
}
139
181
}
140
182
183
+ /**
184
+ * Thrown when an invalid multiaddr is encountered
185
+ */
141
186
export class InvalidMultiaddrError extends Error {
187
+ static name = 'InvalidMultiaddrError'
188
+
142
189
constructor ( message = 'Invalid multiaddr' ) {
143
190
super ( message )
144
191
this . name = 'InvalidMultiaddrError'
145
192
}
146
193
}
147
194
195
+ /**
196
+ * Thrown when an invalid CID is encountered
197
+ */
148
198
export class InvalidCIDError extends Error {
199
+ static name = 'InvalidCIDError'
200
+
149
201
constructor ( message = 'Invalid CID' ) {
150
202
super ( message )
151
203
this . name = 'InvalidCIDError'
152
204
}
153
205
}
154
206
207
+ /**
208
+ * Thrown when an invalid multihash is encountered
209
+ */
155
210
export class InvalidMultihashError extends Error {
211
+ static name = 'InvalidMultihashError'
212
+
156
213
constructor ( message = 'Invalid Multihash' ) {
157
214
super ( message )
158
215
this . name = 'InvalidMultihashError'
159
216
}
160
217
}
161
218
219
+ /**
220
+ * Thrown when a protocol is not supported
221
+ */
162
222
export class UnsupportedProtocolError extends Error {
223
+ static name = 'UnsupportedProtocolError'
224
+
163
225
constructor ( message = 'Unsupported protocol error' ) {
164
226
super ( message )
165
227
this . name = 'UnsupportedProtocolError'
@@ -170,69 +232,120 @@ export class UnsupportedProtocolError extends Error {
170
232
* An invalid or malformed message was encountered during a protocol exchange
171
233
*/
172
234
export class InvalidMessageError extends Error {
235
+ static name = 'InvalidMessageError'
236
+
173
237
constructor ( message = 'Invalid message' ) {
174
238
super ( message )
175
239
this . name = 'InvalidMessageError'
176
240
}
177
241
}
178
242
243
+ /**
244
+ * Thrown when a remote peer sends a structurally valid message that does not
245
+ * comply with the protocol
246
+ */
179
247
export class ProtocolError extends Error {
248
+ static name = 'ProtocolError'
249
+
180
250
constructor ( message = 'Protocol error' ) {
181
251
super ( message )
182
252
this . name = 'ProtocolError'
183
253
}
184
254
}
185
255
256
+ /**
257
+ * Throw when an operation times out
258
+ */
186
259
export class TimeoutError extends Error {
260
+ static name = 'TimeoutError'
261
+
187
262
constructor ( message = 'Timed out' ) {
188
263
super ( message )
189
264
this . name = 'TimeoutError'
190
265
}
191
266
}
192
267
268
+ /**
269
+ * Thrown when a startable component is interacted with but it has not been
270
+ * started yet
271
+ */
193
272
export class NotStartedError extends Error {
273
+ static name = 'NotStartedError'
274
+
194
275
constructor ( message = 'Not started' ) {
195
276
super ( message )
196
277
this . name = 'NotStartedError'
197
278
}
198
279
}
199
280
281
+ /**
282
+ * Thrown when a component is started that has already been started
283
+ */
200
284
export class AlreadyStartedError extends Error {
285
+ static name = 'AlreadyStartedError'
286
+
201
287
constructor ( message = 'Already started' ) {
202
288
super ( message )
203
289
this . name = 'AlreadyStartedError'
204
290
}
205
291
}
206
292
293
+ /**
294
+ * Thrown when dialing an address failed
295
+ */
207
296
export class DialError extends Error {
297
+ static name = 'DialError'
298
+
208
299
constructor ( message = 'Dial error' ) {
209
300
super ( message )
210
301
this . name = 'DialError'
211
302
}
212
303
}
213
304
305
+ /**
306
+ * Thrown when listening on an address failed
307
+ */
214
308
export class ListenError extends Error {
309
+ static name = 'ListenError'
310
+
215
311
constructor ( message = 'Listen error' ) {
216
312
super ( message )
217
313
this . name = 'ListenError'
218
314
}
219
315
}
220
316
317
+ /**
318
+ * This error is thrown when a limited connection is encountered, i.e. if the
319
+ * user tried to open a stream on a connection for a protocol that is not
320
+ * configured to run over limited connections.
321
+ */
221
322
export class LimitedConnectionError extends Error {
323
+ static name = 'LimitedConnectionError'
324
+
222
325
constructor ( message = 'Limited connection' ) {
223
326
super ( message )
224
327
this . name = 'LimitedConnectionError'
225
328
}
226
329
}
227
330
331
+ /**
332
+ * This error is thrown where there are too many inbound protocols streams open
333
+ */
228
334
export class TooManyInboundProtocolStreamsError extends Error {
335
+ static name = 'TooManyInboundProtocolStreamsError'
336
+
229
337
constructor ( message = 'Too many inbound protocol streams' ) {
230
338
super ( message )
231
339
this . name = 'TooManyInboundProtocolStreamsError'
232
340
}
233
341
}
234
342
343
+ /**
344
+ * This error is thrown where there are too many outbound protocols streams open
345
+ */
235
346
export class TooManyOutboundProtocolStreamsError extends Error {
347
+ static name = 'TooManyOutboundProtocolStreamsError'
348
+
236
349
constructor ( message = 'Too many outbound protocol streams' ) {
237
350
super ( message )
238
351
this . name = 'TooManyOutboundProtocolStreamsError'
@@ -243,6 +356,8 @@ export class TooManyOutboundProtocolStreamsError extends Error {
243
356
* Thrown when and attempt to operate on an unsupported key was made
244
357
*/
245
358
export class UnsupportedKeyTypeError extends Error {
359
+ static name = 'UnsupportedKeyTypeError'
360
+
246
361
constructor ( message = 'Unsupported key type' ) {
247
362
super ( message )
248
363
this . name = 'UnsupportedKeyTypeError'
0 commit comments