Skip to content

Instantly share code, notes, and snippets.

@iarna
Created March 3, 2014 21:28
Show Gist options
  • Save iarna/9334983 to your computer and use it in GitHub Desktop.
Save iarna/9334983 to your computer and use it in GitHub Desktop.
Error domain bug in Node 0.10 (seems fixed in 0.11)
var soon = process.nextTick;
require('domain').create()
.on('error', function(E){ console.log("All is well soon") })
.run(function() {
soon(function(){ throw new Error() })
});
// We expect "All is well soon" to be logged
// Instead we get:
/*
fail1.js:6
soon(function(){ throw new Error() })
^
Error
at fail1.js:6:32
at process._tickDomainCallback (node.js:459:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:902:3
*/
require('domain').create()
.on('error', function(E){ console.log("This shouldn't be called") })
.run(function() { });
var soon = process.nextTick;
require('domain').create()
.on('error', function(E){ console.log("All is well soon") })
.run(function() {
soon(function(){ throw new Error() })
});
// We expect and get "All is well soon"
// Note that the only difference between this and fail1 is the empty failure domain at the top
require('domain').create()
.on('error', function(E){ console.log("All is well nextTick") })
.run(function() {
process.nextTick(function(){ throw new Error() })
});
// We expect and get "all is well nextTick" logged
@iarna
Copy link
Author

iarna commented Mar 3, 2014

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