git-annex/Annex/Exception.hs
Joey Hess f3a2f60abc adjust to build with monad-control-0.3
I had to, I hope temporarily, lose my nice Annex newtype, and use a type
synonym. This because I cannot find a way to derive a MonadBaseControl
instance of the Annex newtype. I've emailed Bas van Dijk in hope he can
help get the newtype back.

Otherwise appears to build & work.
2011-12-05 22:51:37 -04:00

27 lines
725 B
Haskell

{- exception handling in the git-annex monad
-
- Copyright 2011 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Annex.Exception (
bracketIO,
handle,
throw,
) where
import Control.Exception.Lifted (handle)
import Control.Monad.Trans.Control (liftBaseOp)
import Control.Exception hiding (handle, throw)
import Common.Annex
{- Runs an Annex action, with setup and cleanup both in the IO monad. -}
bracketIO :: IO c -> (c -> IO b) -> Annex a -> Annex a
bracketIO setup cleanup go =
liftBaseOp (Control.Exception.bracket setup cleanup) (const go)
{- Throws an exception in the Annex monad. -}
throw :: Control.Exception.Exception e => e -> Annex a
throw = liftIO . throwIO