2011-10-04 04:34:04 +00:00
|
|
|
{- 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,
|
2012-09-24 17:16:50 +00:00
|
|
|
tryAnnex,
|
2011-10-04 04:34:04 +00:00
|
|
|
throw,
|
|
|
|
) where
|
|
|
|
|
2012-09-24 17:16:50 +00:00
|
|
|
import Control.Exception.Lifted (handle, try)
|
2011-12-06 02:51:37 +00:00
|
|
|
import Control.Monad.Trans.Control (liftBaseOp)
|
2012-09-24 17:16:50 +00:00
|
|
|
import Control.Exception hiding (handle, try, throw)
|
2011-10-04 04:34:04 +00:00
|
|
|
|
2011-10-05 20:02:51 +00:00
|
|
|
import Common.Annex
|
2011-10-04 04:34:04 +00:00
|
|
|
|
|
|
|
{- 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 =
|
2011-12-06 02:51:37 +00:00
|
|
|
liftBaseOp (Control.Exception.bracket setup cleanup) (const go)
|
2011-10-04 04:34:04 +00:00
|
|
|
|
2012-09-24 17:16:50 +00:00
|
|
|
{- try in the Annex monad -}
|
|
|
|
tryAnnex :: Annex a -> Annex (Either SomeException a)
|
|
|
|
tryAnnex = try
|
|
|
|
|
2011-10-04 04:34:04 +00:00
|
|
|
{- Throws an exception in the Annex monad. -}
|
|
|
|
throw :: Control.Exception.Exception e => e -> Annex a
|
|
|
|
throw = liftIO . throwIO
|