Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

domain.on('error') should suppress other uncaughtException handlers #4375

Closed
@CrabBot

Description

Coming from a mocha issue, I realized the following:

  • domains do not "catch" errors in the sense that uncaughtException will still fire, an implementation detail probably best kept out of userland.
  • In a sense, this is inconsistent with the EventEmitter API where EventEmitter.on('error') suppresses errors from being thrown, where as uncaughtException firing is a de facto failure to catch

Example:

process.on('uncaughtException', function(err) {
  console.error(err.stack)
  // Uh oh! Do as the docs recommend & bail
  process.exit()
})

var domain = require('domain').create()
domain.on('error', function(err) {
  // Proceed. We're totally cool
  console.error(err.stack)
  domain.dispose()
})
domain.run(function() {
  process.nextTick(function() {
    throw new Error('fail')
  })
})

A possible workaround would be to wrap your uncaughtException handler in a process.nextTick and then check for err.domain, but that means domains are backwards incompatible with existing uncaughtException handlers for example in 3rd party modules like mocha.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions