effection
effection copied to clipboard
Where should warning go if an exception percolates to the top.
Node has an UnhandledPromiseRejection warning that is spewed if you ever create a promise that rejects that isn't explicitly handled. This can be very annoying, but it is actually quite useful in that it usually means that you are dropping errors somewhere. This code for example is completely silent:
import { run } from 'effection';
run(function*() {
throw new Error('Ka boom!");
});
//=> crickets !!
In this case, the error is propagating to the root task which is ignoring it. However, the most elegant mechanism to me seems to me would be to have the root task have an error boundary that printed out a warning... In other words, don't let errors percolate all the way up to the root task.
The problem is that there are legit cases where percolating a failure to the root is intentional, such as when using run(...).catch(). It can be challenging to distinguish when it is intended and when not. node I assume does some trickery with promises by tracking listeners to the promise, unfortunately we don't really have that option. There are some heuristics we could do, but it seems pretty difficult, if not impossible to do this correctly.
And false warnings are incredibly annoying, so we should be careful with that.
Agree. Let's leave this open for now, and we can have a think on it later.