diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2020-01-02 18:07:10 +0000 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2020-01-02 18:07:10 +0000 |
commit | 1092316ba04116d7ae1d4cdf347804feacef768a (patch) | |
tree | fbc819794d4202a4ac778f0f6be57eedef7518dd /Utility/Exception.hs | |
parent | d1e0531dd8e8b842349421a898b74b212d2157e8 (diff) | |
parent | 50a5a7b101cc9c30a5a04b4c20cbf7f99fcab0ef (diff) | |
download | git-repair-1092316ba04116d7ae1d4cdf347804feacef768a.tar.gz |
Merge tag '1.20200102'
tagging package git-repair version 1.20200102
Diffstat (limited to 'Utility/Exception.hs')
-rw-r--r-- | Utility/Exception.hs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/Utility/Exception.hs b/Utility/Exception.hs index 8b110ae..bcadb78 100644 --- a/Utility/Exception.hs +++ b/Utility/Exception.hs @@ -1,6 +1,6 @@ {- Simple IO exception handling (and some more) - - - Copyright 2011-2015 Joey Hess <id@joeyh.name> + - Copyright 2011-2016 Joey Hess <id@joeyh.name> - - License: BSD-2-clause -} @@ -10,6 +10,7 @@ module Utility.Exception ( module X, + giveup, catchBoolIO, catchMaybeIO, catchDefaultIO, @@ -21,12 +22,14 @@ module Utility.Exception ( tryNonAsync, tryWhenExists, catchIOErrorType, - IOErrorType(..) + IOErrorType(..), + catchPermissionDenied, ) where import Control.Monad.Catch as X hiding (Handler) import qualified Control.Monad.Catch as M import Control.Exception (IOException, AsyncException) +import Control.Exception (SomeAsyncException) import Control.Monad import Control.Monad.IO.Class (liftIO, MonadIO) import System.IO.Error (isDoesNotExistError, ioeGetErrorType) @@ -34,6 +37,13 @@ import GHC.IO.Exception (IOErrorType(..)) import Utility.Data +{- Like error, this throws an exception. Unlike error, if this exception + - is not caught, it won't generate a backtrace. So use this for situations + - where there's a problem that the user is excpected to see in some + - circumstances. -} +giveup :: [Char] -> a +giveup = errorWithoutStackTrace + {- Catches IO errors and returns a Bool -} catchBoolIO :: MonadCatch m => m Bool -> m Bool catchBoolIO = catchDefaultIO False @@ -73,6 +83,7 @@ bracketIO setup cleanup = bracket (liftIO setup) (liftIO . cleanup) catchNonAsync :: MonadCatch m => m a -> (SomeException -> m a) -> m a catchNonAsync a onerr = a `catches` [ M.Handler (\ (e :: AsyncException) -> throwM e) + , M.Handler (\ (e :: SomeAsyncException) -> throwM e) , M.Handler (\ (e :: SomeException) -> onerr e) ] @@ -97,3 +108,6 @@ catchIOErrorType errtype onmatchingerr a = catchIO a onlymatching onlymatching e | ioeGetErrorType e == errtype = onmatchingerr e | otherwise = throwM e + +catchPermissionDenied :: MonadCatch m => (IOException -> m a) -> m a -> m a +catchPermissionDenied = catchIOErrorType PermissionDenied |