Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Q unhandled rejection reasons with Q.all

I get this warning for code below and I don't understand why.

It's similar to this question: Unhandled rejection reasons (should be empty)

but ...

I'm pretty sure I am handling all errors, so why the warning?

Here is JSFiddle: http://jsfiddle.net/yoorek/jLLbR/

function run(number) {
    var deferred = Q.defer();

    if (number % 2) {
        deferred.reject(new Error('Error for ' + number));
    } else {
        deferred.resolve(number);
    }

    return deferred.promise;
}

var promises = [], data = [1, 2, 3, 4, 5];

data.forEach(function (item) {
    var promise;

    promise = run(item)
        .then(function (result) {
            log.info('Success : ' + result);
        })
        .catch (function (error) {
            log.info('Error Handler in loop ' + error.message);
        });

    promises.push(promise);
});

Q.all(promises)
    .then(function () {
        log.info('All Success');
    })
    .catch (function (error) {
        log.info('Error handler for All ' + error.message);
    });
like image 284
Yoorek Avatar asked Nov 02 '22 01:11

Yoorek


1 Answers

This was a bug with how Q did unhandled rejections. It didn't detect unhandled rejections very well and the feature was removed.

Update your version of Q from 1.0.0 , or use Bluebird which does error tracking properly.

Here's an updated fiddle

like image 128
Benjamin Gruenbaum Avatar answered Nov 08 '22 07:11

Benjamin Gruenbaum