-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Uncaught exception helper #771
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
Comments
Is there a babel plugin out there to do this? |
No, it would mean developing our own - similar to |
I like the idea. Any potential drawbacks? And we're probably never going to use domains anyways. |
It wouldn't extend to library code but that can't be helped really. I like it! |
Looking into doing this since I'm interested in learning Babel stuff—just need more info. Are we just turning all anonymous callbacks inside tests to arguments to |
Hey @sotojuan - I've got a start on this already. I'm happy to give you a crack at it though. I'll push up what I've got and you can roll from there. |
@jamestalmage It's fine! It was either this or the tape -> AVA codemods. I'll work on those instead. |
👍 You should familiarize yourself with If you find it overwhelming initially, then you're in the same boat as everybody else. Feel free to open issues on those projects or ping me on |
Oh also make sure you start with |
this will work for one level of code - good idea - but instead of letting the error go to global scope I would suggest just using the value for self/this since you already have it in hand. |
is Babel capable of doing this for all types of asynchronous callbacks? for example, Babel might recognize this: test('foo', t => {
setTimeout(function(){
}, 100);
}); and convert it to test('foo', t => {
setTimeout(t.__wrapFn(function(){
}), 100);
}); but what about something like this: test('foo', t => {
client.get('redis_key', function(err, reply){
});
}); that would need to become: test('foo', t => {
client.get('redis_key', t.__wrapFn(function(err, reply){
}));
}); I guess Babel can do that without any problems |
It can do it for the examples you listed, however there would be scenarios where it wouldn't work: function commonCallback () {
throw new Exception('this is uncaught');
}
test(t => {
client.get('redis_key', commonCallback);
}); |
Ok that's interesting, so yeah maybe on top of the Babel plugin you should make users aware of the potential need to manually call t.__wrap and in that case perhaps alias it with t.wrap = t.__wrap or whatever. |
I keep wondering if it wouldn't just be easier to do domains. Domains would neatly handle everything this proposal would, plus some stuff it wouldn't. |
domains don't work with ES6 promises yet, which is a big problem, supposedly someone special is going to patch this at some point soon. |
Yeah, that's not great. They seem to work with |
Wrapping declarations is tricky given generators and async functions. The wrapped code suddenly runs in a non-generator/async function context, and will crash. We've recently improved detection of hanging tests; throwing an uncaught exception before Aside from #583 I think we've done as much as we can to handle this scenario. |
As an alternative (or possibly in addition) to using domains to try and track the source of an uncaught exception, what if we used a babel plugin to wrap function declarations?
Becomes:
t.__wrapFn
would just mark the error with the associated test before letting it continue to bubble up:Our
uncaughtException
handler could then detect the special property and fail the specific associated test instead of killing the whole process.The text was updated successfully, but these errors were encountered: