UNPKG

2.8 kBTypeScriptView Raw
1declare namespace PluginError {
2 interface Constructor {
3 /**
4 * @param plugin Plugin name
5 * @param error Base error
6 * @param options Error options
7 */
8 new <E extends Error>(
9 plugin: string,
10 error: E,
11 options?: Options
12 ): PluginError<E>;
13
14 /**
15 * @param plugin Plugin name
16 * @param error Base error or error message
17 * @param options Error options
18 */
19 new <E extends Error = Error>(
20 plugin: string,
21 error: E | string,
22 options: Options
23 ): PluginError<E | { [K in keyof E]: undefined }>;
24
25 /**
26 * @param plugin Plugin name
27 * @param error Base error, error message, or options with message
28 */
29 new <E extends Error = Error>(
30 plugin: string,
31 error: E | string | (Options & { message: string })
32 ): PluginError<E | { [K in keyof E]: undefined }>;
33
34 /**
35 * @param options Options with plugin name and message
36 */
37 new (options: Options & { plugin: string; message: string }): PluginError;
38 }
39
40 interface Options {
41 /**
42 * Error name
43 */
44 name?: string;
45
46 /**
47 * Error message
48 */
49 message?: any;
50
51 /**
52 * File name where the error occurred
53 */
54 fileName?: string;
55
56 /**
57 * Line number where the error occurred
58 */
59 lineNumber?: number;
60
61 /**
62 * Error properties will be included in err.toString(). Can be omitted by
63 * setting this to false.
64 *
65 * Default: `true`
66 */
67 showProperties?: boolean;
68
69 /**
70 * By default the stack will not be shown. Set this to true if you think the
71 * stack is important for your error.
72 *
73 * Default: `false`
74 */
75 showStack?: boolean;
76
77 /**
78 * Error stack to use for `err.toString()` if `showStack` is `true`.
79 * By default it uses the `stack` of the original error if you used one, otherwise it captures a new stack.
80 */
81 stack?: string;
82 }
83
84 /**
85 * The `SimplePluginError` interface defines the properties available on all the the instances of `PluginError`.
86 *
87 * @internal
88 */
89 interface SimplePluginError extends Error {
90 /**
91 * Plugin name
92 */
93 plugin: string;
94
95 /**
96 * Boolean controlling if the stack will be shown in `err.toString()`.
97 */
98 showStack: boolean;
99
100 /**
101 * Boolean controlling if properties will be shown in `err.toString()`.
102 */
103 showProperties: boolean;
104
105 /**
106 * File name where the error occurred
107 */
108 fileName?: string;
109
110 /**
111 * Line number where the error occurred
112 */
113 lineNumber?: number;
114 }
115}
116
117/**
118 * Abstraction for error handling for Vinyl plugins
119 */
120type PluginError<T = {}> = PluginError.SimplePluginError & T;
121
122declare const PluginError: PluginError.Constructor;
123
124export = PluginError;