rkatic/p

error not caught when using domains

Closed this issue · 3 comments

I'm trying to use domains to catch errors in certain contexts. When I call done() at the end of a promise chain to ensure failures are raised as exceptions, these exceptions somehow leak out of the domain. Here's a simple example of the problem - switch it out to use Q to see the behaviour I was expecting:

var p = require('p-promise');
//var p = require('Q');

var domain = require('domain'),
    d = domain.create();

d.on('error', function (err) {
    console.log('got error in domain:', err.message);
});

process.on('error', function (err) {
    console.log('got error in process:', err.message);
});

d.run(function () {
    var deferred = p.defer();
    deferred.promise.done();
    deferred.reject(new Error('foo'));
});

Thanks

Tom

@tomyan I somehow overlooked this. Sorry :(

Currently P doesn't support domains, but I plan to use ASAP pretty soon (which will be used by Q too) and to build p.js with browserfy. ASAP supports domains even more properly then Q does currently, which should resolve the issue.

With last changes I also added support for domains.
However, it is still not tested properly.
Will close this when I will have some domain related tests.

With 8fb323b I added some domain related tests. From now, P supports domains.