vorpal
vorpal copied to clipboard
Bug: Rejected promises are handled incorrectly (process returns zero status code)
Hello!
Thank you for this great library!
However, the rejected promises, which are returned from the commands are handled incorrectly.
I've created a simple repository to demonstrate the issue: https://github.com/slavafomin/vorpal-promise-rejection-issue
Here's the minimal example:
const vorpal = require('vorpal')();
vorpal
.command('test-callback')
.action((args, callback) =>
setTimeout(() =>
callback(new Error('Something bad happened...')), 500
)
)
;
vorpal
.command('test-promise')
.action(args =>
new Promise((resolve, reject) =>
setTimeout(() =>
reject(new Error('Something bad happened...')), 500
)
)
)
;
// vorpal.parse(['', '', 'test-callback']);
vorpal.parse(['', '', 'test-promise']);
When callback is used, then error is logged to the console and process exists with non-zero status code. However, when rejected promise is returned, then the Unhandled promise rejection warning is generated and process exits with zero code (which is a bug).
This is an annoying error. I have to wrap all my actions with error handlers.