Skip to content
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

bracketP with custom monad stack #489

Open
emlautarom1 opened this issue Jun 3, 2022 · 1 comment
Open

bracketP with custom monad stack #489

emlautarom1 opened this issue Jun 3, 2022 · 1 comment

Comments

@emlautarom1
Copy link

I have the following function:

withPostgreSQL :: MonadResource m => ByteString -> (SQL.Connection -> ConduitT i o m r) -> ConduitT i o m r
withPostgreSQL cs f = bracketP (SQL.connectPostgreSQL cs) SQL.close f

I would like to catch any exception that connectPostgreSQL throws and log it using monad-logger, something like:

withPostgreSQL cs f = (bracketP (SQL.connectPostgreSQL cs) SQL.close f) `catch` (\(e :: IOException) -> $(logError) (show e))

Now it seems that I can't do that since catch from base is fixed to IO. Using catch from unliftIO requires ConduitT to have an instance of MonadUnliftIO. After trying stuff for a while I just gave up.

My question would be "how do I log that bracketP failed using monad-logger"?

@snoyberg
Copy link
Owner

snoyberg commented Jun 6, 2022

You can't do that. You would need to do the exception handling inside the arguments to bracketP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants