1 | /*
|
2 | * VError([cause], fmt[, arg...]): Like JavaScript's built-in Error class, but
|
3 | * supports a "cause" argument (another error) and a printf-style message. The
|
4 | * cause argument can be null or omitted entirely.
|
5 | *
|
6 | * Examples:
|
7 | *
|
8 | * CODE MESSAGE
|
9 | * new VError('something bad happened') "something bad happened"
|
10 | * new VError('missing file: "%s"', file) "missing file: "/etc/passwd"
|
11 | * with file = '/etc/passwd'
|
12 | * new VError(err, 'open failed') "open failed: file not found"
|
13 | * with err.message = 'file not found'
|
14 | */
|
15 | declare class VError extends Error {
|
16 | static VError: typeof VError;
|
17 |
|
18 | static cause(err: Error): Error | null;
|
19 | static info(err: Error): VError.Info;
|
20 | static fullStack(err: Error): string;
|
21 | static findCauseByName(err: Error, name: string): Error | null;
|
22 | static hasCauseWithName(err: Error, name: string): boolean;
|
23 | static errorFromList<T extends Error>(errors: T[]): null | T | VError.MultiError;
|
24 | static errorForEach(err: Error, func: (err: Error) => void): void;
|
25 |
|
26 | cause: () => Error | undefined;
|
27 | constructor(options: VError.Options | Error, message: string, ...params: any[]);
|
28 | constructor(message?: string, ...params: any[]);
|
29 | }
|
30 |
|
31 | declare namespace VError {
|
32 | interface Info {
|
33 | [key: string]: any;
|
34 | }
|
35 |
|
36 | interface Options {
|
37 | cause?: Error | null | undefined;
|
38 | name?: string | undefined;
|
39 | strict?: boolean | undefined;
|
40 | constructorOpt?(...args: any[]): void;
|
41 | info?: Info | undefined;
|
42 | }
|
43 |
|
44 | /*
|
45 | * SError is like VError, but stricter about types. You cannot pass "null" or
|
46 | * "undefined" as string arguments to the formatter. Since SError is only a
|
47 | * different function, not really a different class, we don't set
|
48 | * SError.prototype.name.
|
49 | */
|
50 | class SError extends VError {}
|
51 |
|
52 | /*
|
53 | * Represents a collection of errors for the purpose of consumers that generally
|
54 | * only deal with one error. Callers can extract the individual errors
|
55 | * contained in this object, but may also just treat it as a normal single
|
56 | * error, in which case a summary message will be printed.
|
57 | */
|
58 | class MultiError extends VError {
|
59 | constructor(errors: Error[]);
|
60 | errors(): Error[];
|
61 | }
|
62 |
|
63 | /*
|
64 | * Like JavaScript's built-in Error class, but supports a "cause" argument which
|
65 | * is wrapped, not "folded in" as with VError. Accepts a printf-style message.
|
66 | * The cause argument can be null.
|
67 | */
|
68 | class WError extends VError {}
|
69 | }
|
70 |
|
71 | export = VError;
|