Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Domain is pinned to rejected Promise, but domain is not caught #831

Closed
ORESoftware opened this issue Sep 20, 2017 · 3 comments
Closed

Domain is pinned to rejected Promise, but domain is not caught #831

ORESoftware opened this issue Sep 20, 2017 · 3 comments

Comments

@ORESoftware
Copy link

ORESoftware commented Sep 20, 2017

Using this code:

const Domain = require('domain');
const d = Domain.create();

process.once('unhandledRejection', function(r, p){
  console.log('unhandledRejection', r, p);
});

d.once('error', function(){
  console.log('domain caught');
});


d.run(function(){
  Promise.resolve(null).then(function(){
    throw 'foo';
  });
});

the domain error event handler won't be touched -> the exception will be sent to the unhandledRejection handler, but the promise will have the domain instance pinned to it. I assume this is expected behavior, but since we have the domain, why not fire it's error event instead of firing unhandledRejection?

@benjamingr
Copy link
Member

Because that's not how promises with domains work - the error handling model is still promises.

Thanks for the question.

@misterdjules
Copy link

@ORESoftware

See https://nodejs.org/api/domain.html#domain_domains_and_promises:

Note that domains will not interfere with the error handling mechanisms for Promises, i.e. no error event will be emitted for unhandled Promise rejections.

@ORESoftware
Copy link
Author

Alrighty, I can see why that decision was made, and I am glad that I can access the domain instance, I was just curious if it was expected behavior. Thanks all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants