UNPKG

824 BJavaScriptView Raw
1'use strict';
2const debug = require('debug');
3const { autoExit } = require('./unref-timeout');
4const { red } = require('colors');
5const { FilterChain } = require('./error-processor');
6const filterChain = new FilterChain();
7const handler = function (err) {
8 // err may be null when fun local || fun build || fun install
9 filterChain.process(err.message, err).then(processed => {
10 // If the verbose option is true, in addition to the message,
11 // print the stack of the error.
12 if (debug.enabled('*') && err.stack) {
13 console.error(err.stack);
14 }
15 else if (err.message) {
16 console.error(red(err.message));
17 }
18 else {
19 console.error(err);
20 }
21 process.exitCode = -1;
22 autoExit(-1);
23 });
24};
25module.exports = handler;