The current behaviour of bracket causes the following expression to throw inside release. However, this is behaviour doesn't work for my use-case.
Which standard Haskell function would throw the original exception raised by the core action, i.e. it will throw inside action?
bracket
(pure ()) -- acquire resource
(const $ UnliftIO.throwString "inside release") -- release resource
(const $ UnliftIO.throwString "inside action") -- action which uses the resource
Why do I need this? In my case the "resource" is running an SQL statement which will effect the SQL connection as long as the session exists. I want to make sure that the effect of that SQL statement is always undone via "release resource". However, if the "core action" itself has an SQL error, then "release resource" always fails with current transaction is aborted, commands ignored until end of transaction block which completely gobbles-up the core/underlying exception thrown by the action.
It seems to me you could just catch the error inside the release function:
bracket
(pure ())
(const $
catch
(UnliftIO.throwString "inside release")
(\(_ :: StringException) -> pure ()))
(const $ UnliftIO.throwString "inside action")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With