Skip to content

Commit

Permalink
Include error.stack if the callback was called again with an Error.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex J Burke committed Oct 2, 2014
1 parent a4af0cc commit 0f165bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/passError.js
Expand Up @@ -14,7 +14,7 @@
var called = false;
return function (err) { // ...
if (called) {
throw new Error('passError: The callback was called more than once');
throw new Error('passError: The callback was called again with ' + (err ? err.stack : 'no error'));
}
called = true;
if (err) {
Expand Down
16 changes: 14 additions & 2 deletions test/passError.js
Expand Up @@ -28,11 +28,23 @@ describe('passError', function () {
expect(successCallback, 'was not called');
});

it('should throw an error if called twice', function () {
it('should throw an error if called again', function () {
cb();
expect(errorCallback, 'was not called');
expect(successCallback, 'was called once');
expect(cb, 'to throw exception', 'passError: The callback was called more than once');
expect(cb, 'to throw exception', 'passError: The callback was called again with no error');
expect(errorCallback, 'was not called');
expect(successCallback, 'was called once');
});

it('should throw an error including the stack if called again with an error', function () {
cb();
expect(errorCallback, 'was not called');
expect(successCallback, 'was called once');
var err = new Error('testing testing 123');
expect(function () {
cb(err);
}, 'to throw exception', 'passError: The callback was called again with ' + err.stack);
expect(errorCallback, 'was not called');
expect(successCallback, 'was called once');
});
Expand Down

0 comments on commit 0f165bf

Please sign in to comment.