UNPKG

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