LIB: improve exception handling
This commit is contained in:
parent
038b0d0377
commit
17407860f4
@ -199,6 +199,15 @@ catchErrno en a1 a2 =
|
|||||||
else ioError e
|
else ioError e
|
||||||
|
|
||||||
|
|
||||||
|
-- |Execute the given action and retrow IO exceptions that have the given errno.
|
||||||
|
rethrowErrnoAs :: Errno -- ^ errno to catch
|
||||||
|
-> FmIOException -- ^ rethrow as
|
||||||
|
-> IO a -- ^ action to try
|
||||||
|
-> IO a
|
||||||
|
rethrowErrnoAs en fmex action = catchErrno en action (throw fmex)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- |Like `catchIOError`, with arguments swapped.
|
-- |Like `catchIOError`, with arguments swapped.
|
||||||
handleIOError :: (IOError -> IO a) -> IO a -> IO a
|
handleIOError :: (IOError -> IO a) -> IO a -> IO a
|
||||||
handleIOError a1 a2 = catchIOError a2 a1
|
handleIOError a1 a2 = catchIOError a2 a1
|
||||||
|
@ -52,6 +52,10 @@ import Data.Time.Clock.POSIX
|
|||||||
, posixSecondsToUTCTime
|
, posixSecondsToUTCTime
|
||||||
)
|
)
|
||||||
import Data.Time()
|
import Data.Time()
|
||||||
|
import Foreign.C.Error
|
||||||
|
(
|
||||||
|
eACCES
|
||||||
|
)
|
||||||
import HPath
|
import HPath
|
||||||
(
|
(
|
||||||
Abs
|
Abs
|
||||||
@ -60,6 +64,7 @@ import HPath
|
|||||||
, pattern Path
|
, pattern Path
|
||||||
)
|
)
|
||||||
import qualified HPath as P
|
import qualified HPath as P
|
||||||
|
import HSFM.FileSystem.Errors
|
||||||
import HSFM.Utils.MyPrelude
|
import HSFM.Utils.MyPrelude
|
||||||
import Prelude hiding(readFile)
|
import Prelude hiding(readFile)
|
||||||
import System.IO.Error
|
import System.IO.Error
|
||||||
@ -608,7 +613,8 @@ getDirsFiles' :: (Path Fn -> [Path Fn] -> [Path Fn]) -- ^ filter function
|
|||||||
-> Path Abs -- ^ dir to read
|
-> Path Abs -- ^ dir to read
|
||||||
-> IO [Path Fn]
|
-> IO [Path Fn]
|
||||||
getDirsFiles' filterf fp =
|
getDirsFiles' filterf fp =
|
||||||
bracket (PFD.openDirStream . P.toFilePath $ fp)
|
rethrowErrnoAs eACCES (Can'tOpenDirectory . P.fpToString . P.fromAbs $ fp)
|
||||||
|
$ bracket (PFD.openDirStream . P.toFilePath $ fp)
|
||||||
PFD.closeDirStream
|
PFD.closeDirStream
|
||||||
$ \dirstream ->
|
$ \dirstream ->
|
||||||
let mdirs :: [Path Fn] -> IO [Path Fn]
|
let mdirs :: [Path Fn] -> IO [Path Fn]
|
||||||
|
Loading…
Reference in New Issue
Block a user