effection icon indicating copy to clipboard operation
effection copied to clipboard

Where should warning go if an exception percolates to the top.

Open cowboyd opened this issue 4 years ago • 3 comments

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.

cowboyd avatar Apr 16 '21 08:04 cowboyd

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.

jnicklas avatar Jun 22 '21 12:06 jnicklas

And false warnings are incredibly annoying, so we should be careful with that.

jnicklas avatar Jun 22 '21 12:06 jnicklas

Agree. Let's leave this open for now, and we can have a think on it later.

cowboyd avatar Jun 23 '21 16:06 cowboyd