Skip to content

Commit

Permalink
clean up error formatting when the operation times out
Browse files Browse the repository at this point in the history
Change the logic for errors so it no longer replaces the timeout
error stack with the original error's stack. This way the timeout
is actually a proper error, while the original failure is preserved
as the `failure` member of the timeout error.
  • Loading branch information
demmer committed Jun 16, 2016
1 parent db8a67f commit 996c0d7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
3 changes: 1 addition & 2 deletions lib/bluebird-retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ function retry(func, options) {
err.failure = failure;
}

var timeout = new Error('operation timed out after ' + (now - start) + ' ms, ' + tries + ' tries' + ' failure: ' + err.message);
var timeout = new Error('operation timed out after ' + (now - start) + ' ms, ' + tries + ' tries with error: ' + err.message);
timeout.failure = err;
timeout.code = 'ETIMEDOUT';
timeout.stack = err.stack;
return Promise.reject(timeout);
} else {
var delay = interval - (now - tryStart);
Expand Down
5 changes: 3 additions & 2 deletions test/bluebird-retry.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ describe('bluebird-retry', function() {
throw new Error('unexpected success');
})
.caught(function(err) {
expect(err.message).match(/operation timed out/);
expect(err).match(/operation timed out.*not yet/);
expect(err.message).match(/operation timed out.*not yet/);
expect(err.failure).match(/not yet/);
expect(err.failure.message).match(/not yet/);
expect(countSuccess.count).equal(10);
})
Expand All @@ -120,7 +122,6 @@ describe('bluebird-retry', function() {
throw new Error('unexpected success');
})
.caught(function(err) {
console.log(err.stack)
expect(err).match(/operation timed out.*something bad happened/);
expect(err.message).match(/something bad happened/);
expect(err.message).match(/operation timed out/);
Expand Down

0 comments on commit 996c0d7

Please sign in to comment.