Skip to content

Commit

Permalink
pkg: softens the error handling
Browse files Browse the repository at this point in the history
This removes the global handler for unhandledRejection from the process.
The main run function will no longer call process.exit explicitly

Semver: major
  • Loading branch information
esatterwhite committed Jun 1, 2020
1 parent ce2bbbb commit 3307195
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,24 @@ colors = [
, 'greenBright', 'yellowBright', 'cyanBright'
];

process.on('unhandledRejection', onError);

function onError (err) {
console.error(`${chalk.red(err.name)}: ${err.message}`);
if(parsed && parsed.traceback) {
console.error(chalk.bold(chalk.red(err.stack)));
} else {
console.error('use --traceback for full stacktrace');
}
return conf.get('exitOnError') ? process.exit( err.code || 1 ) : null;
const code = isFinite(err.code) ? err.code : 1

if (conf.get('exitOnError')) {
process.exit(code)
return
}
process.exitCode = code
}

function onComplete(content) {
typeof content === 'string' && console.log( content );
typeof content === 'string' && console.log(content);
if(conf.get('exitOnContent')) {
process.exit(0);
}
Expand Down Expand Up @@ -149,5 +153,4 @@ function run( ){

console.error('unknown command %s', command );
console.error('know commands: %s ', Object.keys( commands ).join(', ') );
process.exit(0);
}

0 comments on commit 3307195

Please sign in to comment.