Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promise.all() doesn't allow for handling exceptions. #142

Closed
cha0s opened this issue Mar 14, 2014 · 4 comments
Closed

Promise.all() doesn't allow for handling exceptions. #142

cha0s opened this issue Mar 14, 2014 · 4 comments

Comments

@cha0s
Copy link

cha0s commented Mar 14, 2014

I was expecting that Promise.all(promises).done(...) would suppress the 'possibly unhandled exception' emission. I may be misunderstanding how this machinery works! Here's a test case:

Promise = require 'bluebird'

promises = [
    new Promise (resolve, reject) -> resolve()
    new Promise (resolve, reject) -> reject new Error "ohnoes"
]

Promise.all(promises).done(
    -> console.log 'resolved!'
    (error) -> console.log error.stack
)

and the output:

$ coffee bluebird-test.coffee 
Error: ohnoes
  at promises (bluebird-test.coffee:12:14)
  at tryCatch2 (node_modules/bluebird/js/main/util.js:74:19)
  at Promise$_resolveFromResolver [as _resolveFromResolver] (node_modules/bluebird/js/main/promise.js:608:13)
  at new Promise (node_modules/bluebird/js/main/promise.js:88:37)
  at Object.<anonymous> (bluebird-test.coffee:10:6)
  at Object.<anonymous> (bluebird-test.coffee:2:1)
  at Module._compile (module.js:449:26)

Possibly unhandled Error: ohnoes
  at promises (bluebird-test.coffee:12:14)
  at tryCatch2 (node_modules/bluebird/js/main/util.js:74:19)
  at Promise$_resolveFromResolver [as _resolveFromResolver] (node_modules/bluebird/js/main/promise.js:608:13)
  at new Promise (node_modules/bluebird/js/main/promise.js:88:37)
  at Object.<anonymous> (bluebird-test.coffee:10:6)
  at Object.<anonymous> (bluebird-test.coffee:2:1)
  at Module._compile (module.js:449:26)

Oh, and in case coffeescript makes you sad, here's the emitted JS:

  var Promise, promises;

  Promise = require('bluebird');

  promises = [
    new Promise(function(resolve, reject) {
      return resolve();
    }), new Promise(function(resolve, reject) {
      return reject(new Error("ohnoes"));
    })
  ];

  Promise.all(promises).done(function() {
    return console.log('resolved!');
  }, function(error) {
    return console.log(error.stack);
  });
@petkaantonov
Copy link
Owner

This is same as #138 which was fixed in a commit but I didn't make a release yet as I don't understand how you would run this in real code because it requires synchronously or immediately rejected promise to be used with .all.

@cha0s
Copy link
Author

cha0s commented Mar 14, 2014

I don't think it is the same error, because it doesn't matter which order the promises are configured in my example, it never marked the error as handled even though it was. Regardless, the latest master does fix the issue, so I'm going to close this. Thanks!

@cha0s cha0s closed this as completed Mar 14, 2014
@petkaantonov
Copy link
Owner

Yea it's not same issue but the fix and underlying problem is the same

@LuisPerez64
Copy link

Wrote a small bit of sample code to test out another possible way of handling this. Since the Promises force Sync/Async behaviors. I am new to the language, and was wondering if this was Syntactically correct, or if I am tripping over some major pitfalls by doing things under this assumption. Link to a JSFiddle Promise.all Catch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants