summaryrefslogtreecommitdiff
path: root/src/Utility/Exception.hs
diff options
context:
space:
mode:
authorJoey Hess2015-12-15 21:09:50 -0400
committerJoey Hess2015-12-15 21:09:50 -0400
commit4d12d728dd1ef087af39de142c0c5422495305b9 (patch)
tree9a28e835a5e7417da1fa674753fb420a26edd9e4 /src/Utility/Exception.hs
parent81f35a5f8df6907dba394b028d2c7bcbf18cdc5f (diff)
parent47a2b72bed3770d3dfb26c4142479c436a11ce55 (diff)
Merge branch 'joeyconfig'
Diffstat (limited to 'src/Utility/Exception.hs')
-rw-r--r--src/Utility/Exception.hs15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/Utility/Exception.hs b/src/Utility/Exception.hs
index 13000e03..8b110ae6 100644
--- a/src/Utility/Exception.hs
+++ b/src/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