Skip to content

bracketP with custom monad stack #489

@emlautarom1

Description

@emlautarom1

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"?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions