UNPKG

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