From c340b2d05241330674697705a5e4b00c7ac1443b Mon Sep 17 00:00:00 2001 From: James Bunton Date: Fri, 30 Oct 2015 10:10:59 +1100 Subject: [PATCH] Augment the last error instead of generating a new one --- q.js | 7 +++---- spec/q-spec.js | 6 ++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/q.js b/q.js index 46f0f7e7..71e2552c 100644 --- a/q.js +++ b/q.js @@ -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) { diff --git a/spec/q-spec.js b/spec/q-spec.js index 1ec6880c..cd218ed0 100644 --- a/spec/q-spec.js +++ b/spec/q-spec.js @@ -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); }