UNPKG

1.55 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.handle = void 0;
4/* eslint-disable no-process-exit */
5/* eslint-disable unicorn/no-process-exit */
6const config_1 = require("./config");
7const pretty_print_1 = require("./errors/pretty-print");
8const clean = require("clean-stack");
9const cli_1 = require("./errors/cli");
10exports.handle = (err) => {
11 var _a, _b, _c;
12 try {
13 if (!err)
14 err = new cli_1.CLIError('no error?');
15 if (err.message === 'SIGINT')
16 process.exit(1);
17 const shouldPrint = !(err.code === 'EEXIT');
18 const pretty = pretty_print_1.default(err);
19 const stack = clean(err.stack || '', { pretty: true });
20 if (shouldPrint) {
21 console.error(pretty ? pretty : stack);
22 }
23 const exitCode = ((_a = err.oclif) === null || _a === void 0 ? void 0 : _a.exit) !== undefined && ((_b = err.oclif) === null || _b === void 0 ? void 0 : _b.exit) !== false ? (_c = err.oclif) === null || _c === void 0 ? void 0 : _c.exit : 1;
24 if (config_1.config.errorLogger && err.code !== 'EEXIT') {
25 if (stack) {
26 config_1.config.errorLogger.log(stack);
27 }
28 config_1.config.errorLogger.flush()
29 .then(() => process.exit(exitCode))
30 .catch(console.error);
31 }
32 else
33 process.exit(exitCode);
34 }
35 catch (error) {
36 console.error(err.stack);
37 console.error(error.stack);
38 process.exit(1);
39 }
40};