generated from Arnesfield/template.ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.ts
68 lines (63 loc) · 2.25 KB
/
error.ts
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
import { NodeData, Options } from './core.types.js';
/** The ArgsTree error options. */
export interface ArgsTreeErrorOptions
extends NodeData,
Pick<ArgsTreeError, 'cause'> {
/** The error message. */
message: string;
}
/** The ArgsTree error object. */
export interface ArgsTreeErrorObject extends ArgsTreeErrorOptions {
/** The error name. */
name: string;
}
/** The ArgsTree error. */
export class ArgsTreeError extends Error implements ArgsTreeErrorObject {
/** Validation failed from provided {@linkcode Options.validate} function. */
static readonly VALIDATE_ERROR = 'validate';
/** The {@linkcode Options} object provided is not valid (e.g. incorrect range). */
static readonly INVALID_OPTIONS_ERROR = 'invalid-options';
/** The option or command did not satisfy the required number of arguments. */
static readonly INVALID_RANGE_ERROR = 'invalid-range';
/** Failed operation for spec builder. */
static readonly INVALID_SPEC_ERROR = 'invalid-spec';
/** After an alias is parsed, it is not recognized as part of {@linkcode Options.alias}. */
static readonly UNRECOGNIZED_ALIAS_ERROR = 'unrecognized-alias';
/** The option or command is not recognized as part of {@linkcode Options.args}. */
static readonly UNRECOGNIZED_ARGUMENT_ERROR = 'unrecognized-argument';
name = 'ArgsTreeError';
/**
* The cause error string.
* - {@linkcode ArgsTreeError.VALIDATE_ERROR}
* - {@linkcode ArgsTreeError.INVALID_OPTIONS_ERROR}
* - {@linkcode ArgsTreeError.INVALID_RANGE_ERROR}
* - {@linkcode ArgsTreeError.INVALID_SPEC_ERROR}
* - {@linkcode ArgsTreeError.UNRECOGNIZED_ALIAS_ERROR}
* - {@linkcode ArgsTreeError.UNRECOGNIZED_ARGUMENT_ERROR}
*/
cause!: string;
raw!: string | null;
alias!: string | null;
args!: string[];
options!: Options;
/**
* The ArgsTree error.
* @param options The error options.
*/
constructor(options: ArgsTreeErrorOptions) {
super(options.message);
// assume options includes all properties (interface is implemented)
Object.assign(this, options);
}
toJSON(): ArgsTreeErrorObject {
return {
name: this.name,
cause: this.cause,
message: this.message,
raw: this.raw,
alias: this.alias,
args: this.args,
options: this.options
};
}
}