Skip to content

Commit

Permalink
Augment the last error instead of generating a new one
Browse files Browse the repository at this point in the history
  • Loading branch information
jbunton-atlassian committed Oct 30, 2015
1 parent 269560a commit c340b2d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 3 additions & 4 deletions q.js
Original file line number Diff line number Diff line change
Expand Up @@ -1625,10 +1625,9 @@ function any(promises) {
function onRejected(err) {
pendingCount--;
if (pendingCount === 0) {
deferred.reject(new Error(
"Q can't get fulfillment value from any promise, all " +
"promises were rejected. Last error: " + err
));
err.message = ("Q can't get fulfillment value from any promise, all " +
"promises were rejected. Last error message: " + err.message);
deferred.reject(err);
}
}
function onProgress(progress) {
Expand Down
6 changes: 4 additions & 2 deletions spec/q-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1206,19 +1206,21 @@ describe("any", function() {

function testReject(promises, deferreds) {
var promise = Q.any(promises);
var expectedError = new Error('Rejected');

for (var index = 0; index < deferreds.length; index++) {
var deferred = deferreds[index];
(function() {
deferred.reject(new Error('Rejected'));
deferred.reject(expectedError);
})();
}

return Q.delay(250)
.then(function() {
expect(promise.isRejected()).toBe(true);
expect(promise.inspect().reason).toBe(expectedError);
expect(promise.inspect().reason.message)
.toBe("Q can't get fulfillment value from any promise, all promises were rejected. Last error: Error: Rejected");
.toBe("Q can't get fulfillment value from any promise, all promises were rejected. Last error message: Rejected");
})
.timeout(1000);
}
Expand Down

0 comments on commit c340b2d

Please sign in to comment.