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