Skip to content

Commit

Permalink
Fix: Avoid swallowing thrown errors in callback argument (closes #43)
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Aug 4, 2017
1 parent 77d00f9 commit 204de69
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var domain = require('domain');

var eos = require('end-of-stream');
var tick = require('next-tick');
var tick = require('process-nextick-args');
var once = require('once');
var exhaust = require('stream-exhaust');

Expand All @@ -25,14 +25,14 @@ function asyncDone(fn, cb) {
}

function onSuccess(result) {
return done(null, result);
tick(done, null, result);
}

function onError(error) {
if (!error) {
error = new Error('Promise rejected without Error');
}
return done(error);
tick(done, error);
}

function asyncRunner() {
Expand All @@ -43,7 +43,7 @@ function asyncDone(fn, cb) {
}

function onCompleted() {
return onSuccess(onNext.state);
onSuccess(onNext.state);
}

if (result && typeof result.on === 'function') {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
},
"dependencies": {
"end-of-stream": "^1.1.0",
"next-tick": "^1.0.0",
"once": "^1.3.2",
"process-nextick-args": "^1.0.7",
"stream-exhaust": "^1.0.1"
},
"devDependencies": {
Expand Down
15 changes: 15 additions & 0 deletions test/promises.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

var domain = require('domain');

var expect = require('expect');

var when = require('when');
Expand Down Expand Up @@ -41,4 +43,17 @@ describe('promises', function() {
done();
});
});

it('does not swallow thrown errors in callback', function(done) {
var d = domain.create();
d.once('error', function(err) {
expect(err).toExist();
done();
});
d.run(function() {
asyncDone(success, function() {
throw new Error('Boom');
});
});
});
});

0 comments on commit 204de69

Please sign in to comment.