UNPKG

1.05 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.inlineString = exports.CLIError = void 0;
7
8/**
9 * A custom Error that creates a single-lined message to match current styling inside CLI.
10 * Uses original stack trace when `originalError` is passed or erase the stack if it's not defined.
11 */
12class CLIError extends Error {
13 constructor(msg, originalError) {
14 super(inlineString(msg));
15
16 if (originalError) {
17 this.stack = typeof originalError === 'string' ? originalError : originalError.stack || ''.split('\n').slice(0, 2).join('\n');
18 } else {
19 // When the "originalError" is not passed, it means that we know exactly
20 // what went wrong and provide means to fix it. In such cases showing the
21 // stack is an unnecessary clutter to the CLI output, hence removing it.
22 delete this.stack;
23 }
24 }
25
26}
27
28exports.CLIError = CLIError;
29
30const inlineString = str => str.replace(/(\s{2,})/gm, ' ').trim();
31
32exports.inlineString = inlineString;
33
34//# sourceMappingURL=errors.js.map
\No newline at end of file