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
|
|
|
|
2018-10-14 16:29:50 -04:00
|
|
|
/** A Deno specific error. The `kind` property is set to a specific error code
|
|
|
|
* which can be used to in application logic.
|
|
|
|
*
|
2019-02-12 10:08:56 -05:00
|
|
|
* try {
|
|
|
|
* somethingThatMightThrow();
|
|
|
|
* } catch (e) {
|
|
|
|
* if (
|
|
|
|
* e instanceof Deno.DenoError &&
|
2020-01-20 10:50:16 -05:00
|
|
|
* e.kind === Deno.ErrorKind.NotFound
|
2019-02-12 10:08:56 -05:00
|
|
|
* ) {
|
2020-01-20 10:50:16 -05:00
|
|
|
* console.error("NotFound error!");
|
2019-02-12 10:08:56 -05:00
|
|
|
* }
|
2018-10-14 16:29:50 -04:00
|
|
|
* }
|
2019-02-12 10:08:56 -05:00
|
|
|
*
|
2018-10-14 16:29:50 -04:00
|
|
|
*/
|
2018-10-07 19:33:30 -04:00
|
|
|
export class DenoError<T extends ErrorKind> extends Error {
|
|
|
|
constructor(readonly kind: T, msg: string) {
|
|
|
|
super(msg);
|
|
|
|
this.name = ErrorKind[kind];
|
2018-08-15 23:36:48 -04:00
|
|
|
}
|
|
|
|
}
|
2019-08-26 17:02:34 -04:00
|
|
|
|
|
|
|
// 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,
|
|
|
|
WouldBlock = 11,
|
|
|
|
InvalidInput = 12,
|
|
|
|
InvalidData = 13,
|
|
|
|
TimedOut = 14,
|
|
|
|
Interrupted = 15,
|
|
|
|
WriteZero = 16,
|
|
|
|
Other = 17,
|
|
|
|
UnexpectedEof = 18,
|
|
|
|
BadResource = 19,
|
2020-01-20 10:50:16 -05:00
|
|
|
UrlParse = 20,
|
|
|
|
Http = 21,
|
|
|
|
TooLarge = 22,
|
|
|
|
InvalidSeekMode = 23,
|
|
|
|
UnixError = 24,
|
|
|
|
InvalidPath = 25,
|
|
|
|
ImportPrefixMissing = 26,
|
|
|
|
Diagnostic = 27,
|
|
|
|
JSError = 28
|
2019-08-26 17:02:34 -04:00
|
|
|
}
|