Skip to content

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

Closed

Description

@ORESoftware

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?

Activity

  1. benjamingr commented on Sep 20, 2017

    @benjamingr
    Member

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

    Thanks for the question.

  2. misterdjules commented on Sep 20, 2017

    @misterdjules

    @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.

  3. ORESoftware commented on Sep 20, 2017

    @ORESoftware
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions