Skip to content

Instantly share code, notes, and snippets.

@tjmehta
Last active October 12, 2015 18:04
Show Gist options
  • Save tjmehta/9c4d4266b93c71465ea0 to your computer and use it in GitHub Desktop.
Save tjmehta/9c4d4266b93c71465ea0 to your computer and use it in GitHub Desktop.
Unexpected domain error handling
var Domain = require('domain')
var d1 = Domain.create();
var emitter;
d1.on('error', handleCreateErr)
d1.run(function () {
emitter = createEmitter()
})
var d2 = Domain.create();
d2.on('error', handleEmitterErr)
d2.run(function () {
emitter.on('foo', function () {
throw new Error('something bad happenned');
})
emitter.emit('foo')
})
function handleCreateErr (err) {
console.error('error creating event emitter', err.stack);
}
function handleEmitterErr (err) {
console.error('error using event emitter', err.stack);
}
@tjmehta
Copy link
Author

tjmehta commented Oct 12, 2015

An error occurs above when using the event emitter, but ends up triggering an error event for d1.
This leads to unexpected behavior, and print the wrong error message (error creating event emitter).

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