vorpal icon indicating copy to clipboard operation
vorpal copied to clipboard

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

Open slavafomin opened this issue 8 years ago • 1 comments

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

slavafomin avatar Oct 10 '17 17:10 slavafomin

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

alancnet avatar May 03 '18 07:05 alancnet