dthree / vorpal

Node's framework for interactive CLIs
http://vorpal.js.org
MIT License
5.63k stars 278 forks source link

Bug: Rejected promises are handled incorrectly (process returns zero status code) #283

Open slavafomin opened 6 years ago

slavafomin commented 6 years ago

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).

alancnet commented 6 years ago

This is an annoying error. I have to wrap all my actions with error handlers.