how to catch/bracket in yesod-1.6?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

how to catch/bracket in yesod-1.6?

Johannes Waldmann-2
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.
Reply | Threaded
Open this post in threaded view
|

Re: how to catch/bracket in yesod-1.6?

Michael Snoyman
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 <[hidden email]> 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.


_______________________________________________
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.
Reply | Threaded
Open this post in threaded view
|

Re: how to catch/bracket in yesod-1.6?

Simon Hafner
In reply to this post by Johannes Waldmann-2
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-Handler.html#t:HandlerFor
[2] https://www.stackage.org/haddock/lts-11.6/resourcet-1.2.1/Control-Monad-Trans-Resource.html#v:allocate
[3] https://www.stackage.org/haddock/lts-11.6/unliftio-0.2.6.0/UnliftIO-Exception.html#v:bracket_

2018-04-25 13:26 GMT+02:00 waldmann <[hidden email]>:

> 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.
_______________________________________________
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.