-
Notifications
You must be signed in to change notification settings - Fork 52
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
Feature request: allow catching of errors thrown from IO #104
Comments
Maybe |
IIRC, it’s possible to do this with just |
@robrix I don't think it is; the signature of
You can call |
This is what we’re doing elsewhere, I believe this was originally based on Oleg’s work: -- | Generalize 'Exc.catch' to other 'MonadIO' contexts for the handler and result.
catchIO :: ( Exc.Exception exc
, MonadIO m
)
=> IO a
-> (exc -> m a)
-> m a
catchIO m handler = liftIO (Exc.try m) >>= either handler pure |
What I'd prefer is
I can write a new effect in our downstream code to do this, if you'd prefer to keep this out of |
This might suggest that |
Retiring this issue in favor of a general |
Right now, it's not necessarily clear that
Control.Effect.Error
can't capture errors that happen in IO. The following code looks like it should return aLeft SomeException
value, since it runs withError SomeException
as a constraint, but if we throw an error inside aLift IO
effect the exception is not caught:I have a branch where I add a
catchIO
function that handles this properly, using theResource
effect to unliftControl.Exception.catch
to an effectful context:I am currently working inside an effect stack that delegates often to IO actions, and every time I call
liftIO
I open myself to the possibility of unhandled exceptions and early termination of my program, so this functionality is a big win to me. I can't see much downside to adding this, though it's arguable that it deserves its own effect rather than being foisted intoResource
, and thatcatchIO
is not the best name. I don't thinkcatch
is appropriate, given that we already providecatchError
.The text was updated successfully, but these errors were encountered: