how to catch/bracket in yesod-1.6?

Dear Cafe, I wonder what's the recommended way to catch an exception, clean up resources, etc., in a yesod Handler. I was using Control.Monad.Catch.bracket_ in legacy code but now I get "No instance for (Control.Monad.Catch.MonadMask (HandlerFor App))" - J

You can use the functions in UnliftIO.Exception, in the unliftio package
https://www.stackage.org/package/unliftio
On Wed, Apr 25, 2018 at 2:26 PM, waldmann wrote: Dear Cafe, I wonder what's the recommended way to catch an exception,
clean up resources, etc., in a yesod Handler.
I was using Control.Monad.Catch.bracket_ in legacy code but now I get
"No instance for (Control.Monad.Catch.MonadMask (HandlerFor App))" - J
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

From the doc [1] there's a few instances you can use. `MonadResource` sounds like the most obvious choice, with its `allocate` [2], but that'll require you to refactor your application a bit. It's what I'd recommend though. If that's unfeasable, there's always the new `bracket_` on `MonadUnliftIO` [3]
[1] https://www.stackage.org/haddock/lts-11.6/yesod-core-1.6.3/Yesod-Core-Handle...
[2] https://www.stackage.org/haddock/lts-11.6/resourcet-1.2.1/Control-Monad-Tran...
[3] https://www.stackage.org/haddock/lts-11.6/unliftio-0.2.6.0/UnliftIO-Exceptio...
2018-04-25 13:26 GMT+02:00 waldmann
Dear Cafe,
I wonder what's the recommended way to catch an exception, clean up resources, etc., in a yesod Handler. I was using Control.Monad.Catch.bracket_ in legacy code but now I get "No instance for (Control.Monad.Catch.MonadMask (HandlerFor App))"
- J _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
participants (3)
-
Michael Snoyman
-
Simon Hafner
-
waldmann