Handling Errors in Effect: Failures vs. Defects
Failures vs. Defects question:
BullMQ has a special Error called WaitingForChildrenError.
this is typically thrown when adding a child job and the parent should wait for children to be done before resuming work. I created a
The problem I see is that this tag could be caught at some level other than root level (where it is supposed to be caught). If I use a defect, nobody can catch and re-map the error that needs to stay the same. Would this justify making a defect out of it for the reason that it mustn't be handled somewhere in the chain?
BullMQ has a special Error called WaitingForChildrenError.
this is typically thrown when adding a child job and the parent should wait for children to be done before resuming work. I created a
Data.TaggedError for it, so I can yield it in my effects. It is handled at the very root of the program (it detects the failure and throws the actual WaitingForChildrenError so BullMQ registers it properly). There are two approaches: Using Effect.fail and Effect.die. I can catch both Failures and Defects in the root. The only difference seems to be that my custom WaitingForChildrenError appears in the Error types of the effects when using a Failure.The problem I see is that this tag could be caught at some level other than root level (where it is supposed to be caught). If I use a defect, nobody can catch and re-map the error that needs to stay the same. Would this justify making a defect out of it for the reason that it mustn't be handled somewhere in the chain?
