summaryrefslogtreecommitdiff
path: root/Utility
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-12-06 16:26:38 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-12-06 16:26:38 -0400
commitcf258d958853d7a9925b3f7abf2b617c5b64499d (patch)
treea5c526d51aeaa18ca2e89558c46334fe372b4a22 /Utility
parent29fe475e490840ffa859b85258353c174b87ee4d (diff)
generalize catchHardwareFault to catchIOErrorType
Diffstat (limited to 'Utility')
-rw-r--r--Utility/Exception.hs15
1 files changed, 8 insertions, 7 deletions
diff --git a/Utility/Exception.hs b/Utility/Exception.hs
index 13000e033..8b110ae6d 100644
--- a/Utility/Exception.hs
+++ b/Utility/Exception.hs
@@ -20,7 +20,8 @@ module Utility.Exception (
catchNonAsync,
tryNonAsync,
tryWhenExists,
- catchHardwareFault,
+ catchIOErrorType,
+ IOErrorType(..)
) where
import Control.Monad.Catch as X hiding (Handler)
@@ -88,11 +89,11 @@ tryWhenExists a = do
v <- tryJust (guard . isDoesNotExistError) a
return (eitherToMaybe v)
-{- Catches only exceptions caused by hardware faults.
- - Ie, disk IO error. -}
-catchHardwareFault :: MonadCatch m => m a -> (IOException -> m a) -> m a
-catchHardwareFault a onhardwareerr = catchIO a onlyhw
+{- Catches only IO exceptions of a particular type.
+ - Ie, use HardwareFault to catch disk IO errors. -}
+catchIOErrorType :: MonadCatch m => IOErrorType -> (IOException -> m a) -> m a -> m a
+catchIOErrorType errtype onmatchingerr a = catchIO a onlymatching
where
- onlyhw e
- | ioeGetErrorType e == HardwareFault = onhardwareerr e
+ onlymatching e
+ | ioeGetErrorType e == errtype = onmatchingerr e
| otherwise = throwM e