-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Domains created inside uncaughtException
event handler don't allow catching errors thrown inside the domain.run()
#22400
Comments
uncaughtException
event don't allow catching errors thrown inside the domain.run()
uncaughtException
event handler don't allow catching errors thrown inside the domain.run()
The reason for this is that when the fatal exception handler throws (and all uncaughtException/domain handlers are invoked from there), Node.js always exits immediately. It might be possible to fix this, but I’m not sure whether we want to do so, given that I think patches would be welcome in either case. |
Thanks, @addaleax for commenting on this. So, I think that domains internally depend on a special I can also closely explain my thoughts on how a domain works as follows: function domainRun({runCb, onErrorCb}) {
process.on('specialUncaughtException', onErrorCb);
runCb();
}
domainRun({
runCb: notExistingFn,
onErrorCb: () => console.log('Caught error within the domain!'),
}); So and to wrap up, the cases (I personally met) that highlight the problem are:
const domain = require('domain');
function foo() {
const createdDomain = domain.create();
createdDomain.on('error', () => console.log('Caught error within the `foo()` domain!'));
createdDomain.run(notExistingFn);
}
try {
foo();
} catch (err) {
console.log('Caught error within the `foo()` try/catch!');
} Workarounds
createdDomain.run(() => process.nextTick(notExistingFn));
function onError(err) {
//...
}
createdDomain.on('error', onError).run(() => {
try {
notExistingFn();
} catch(err) {
onError(err);
}
}); |
Hey, I've closed this issue, as the |
And on contrary to the above scenario, if we call
captureUncaughtException()
directly, it behaves normally.The text was updated successfully, but these errors were encountered: