When working with Effect, if an error occurs, the default behavior is to fail with the first error encountered.
Example (Failing on the First Error)
Here, the program fails with the first error it encounters, "Oh uh!".
Parallel Errors
In some cases, you might encounter multiple errors, especially during concurrent computations. When tasks are run concurrently, multiple errors can happen at the same time.
Example (Handling Multiple Errors in Concurrent Computations)
In this example, both the fail and die effects are executed concurrently. Since both fail, the program will report multiple errors in the output.
parallelErrors
Effect provides a function called Effect.parallelErrors that captures all failure errors from concurrent operations in the error channel.
Example (Capturing Multiple Concurrent Failures)
In this example, Effect.parallelErrors combines the errors from fail1 and fail2 into a single error.
Sequential Errors
When working with resource-safety operators like Effect.ensuring, you may encounter multiple sequential errors.
This happens because regardless of whether the original effect has any errors or not, the finalizer is uninterruptible and will always run.
Example (Handling Multiple Sequential Errors)
In this example, both fail and the finalizer die result in sequential errors, and both are captured.