{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE NoImplicitPrelude #-}
module System.IO.Error (
IOError,
userError,
mkIOError,
annotateIOError,
isAlreadyExistsError,
isDoesNotExistError,
isAlreadyInUseError,
isFullError,
isEOFError,
isIllegalOperation,
isPermissionError,
isUserError,
isResourceVanishedError,
ioeGetErrorType,
ioeGetLocation,
ioeGetErrorString,
ioeGetHandle,
ioeGetFileName,
ioeSetErrorType,
ioeSetErrorString,
ioeSetLocation,
ioeSetHandle,
ioeSetFileName,
IOErrorType,
alreadyExistsErrorType,
doesNotExistErrorType,
alreadyInUseErrorType,
fullErrorType,
eofErrorType,
illegalOperationErrorType,
permissionErrorType,
userErrorType,
resourceVanishedErrorType,
isAlreadyExistsErrorType,
isDoesNotExistErrorType,
isAlreadyInUseErrorType,
isFullErrorType,
isEOFErrorType,
isIllegalOperationErrorType,
isPermissionErrorType,
isUserErrorType,
isResourceVanishedErrorType,
ioError,
catchIOError,
tryIOError,
modifyIOError,
) where
import Control.Exception.Base
import Data.Either
import Data.Maybe
import GHC.Base
import GHC.IO
import GHC.IO.Exception
import GHC.IO.Handle.Types
import Text.Show
tryIOError :: IO a -> IO (Either IOError a)
tryIOError :: forall a. IO a -> IO (Either IOError a)
tryIOError IO a
f = forall e a. Exception e => IO a -> (e -> IO a) -> IO a
catch (do a
r <- IO a
f
forall (m :: * -> *) a. Monad m => a -> m a
return (forall a b. b -> Either a b
Right a
r))
(forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> Either a b
Left)
mkIOError :: IOErrorType -> String -> Maybe Handle -> Maybe FilePath -> IOError
mkIOError :: IOErrorType -> String -> Maybe Handle -> Maybe String -> IOError
mkIOError IOErrorType
t String
location Maybe Handle
maybe_hdl Maybe String
maybe_filename =
IOError{ ioe_type :: IOErrorType
ioe_type = IOErrorType
t,
ioe_location :: String
ioe_location = String
location,
ioe_description :: String
ioe_description = String
"",
ioe_errno :: Maybe CInt
ioe_errno = forall a. Maybe a
Nothing,
ioe_handle :: Maybe Handle
ioe_handle = Maybe Handle
maybe_hdl,
ioe_filename :: Maybe String
ioe_filename = Maybe String
maybe_filename
}
isAlreadyExistsError :: IOError -> Bool
isAlreadyExistsError :: IOError -> Bool
isAlreadyExistsError = IOErrorType -> Bool
isAlreadyExistsErrorType forall b c a. (b -> c) -> (a -> b) -> a -> c
. IOError -> IOErrorType
ioeGetErrorType
isDoesNotExistError :: IOError -> Bool
isDoesNotExistError :: IOError -> Bool
isDoesNotExistError = IOErrorType -> Bool
isDoesNotExistErrorType forall b c a. (b -> c) -> (a -> b) -> a -> c
. IOError -> IOErrorType
ioeGetErrorType
isAlreadyInUseError :: IOError -> Bool
isAlreadyInUseError :: IOError -> Bool
isAlreadyInUseError = IOErrorType -> Bool
isAlreadyInUseErrorType forall b c a. (b -> c) -> (a -> b) -> a -> c
. IOError -> IOErrorType
ioeGetErrorType
isFullError :: IOError -> Bool
isFullError :: IOError -> Bool
isFullError = IOErrorType -> Bool
isFullErrorType forall b c a. (b -> c) -> (a -> b) -> a -> c
. IOError -> IOErrorType
ioeGetErrorType
isEOFError :: IOError -> Bool
isEOFError :: IOError -> Bool
isEOFError = IOErrorType -> Bool
isEOFErrorType forall b c a. (b -> c) -> (a -> b) -> a -> c
. IOError -> IOErrorType
ioeGetErrorType
isIllegalOperation :: IOError -> Bool
isIllegalOperation :: IOError -> Bool
isIllegalOperation = IOErrorType -> Bool
isIllegalOperationErrorType forall b c a. (b -> c) -> (a -> b) -> a -> c
. IOError -> IOErrorType
ioeGetErrorType
isPermissionError :: IOError -> Bool
isPermissionError :: IOError -> Bool
isPermissionError = IOErrorType -> Bool
isPermissionErrorType forall b c a. (b -> c) -> (a -> b) -> a -> c
. IOError -> IOErrorType
ioeGetErrorType
isUserError :: IOError -> Bool
isUserError :: IOError -> Bool
isUserError = IOErrorType -> Bool
isUserErrorType forall b c a. (b -> c) -> (a -> b) -> a -> c
. IOError -> IOErrorType
ioeGetErrorType
isResourceVanishedError :: IOError -> Bool
isResourceVanishedError :: IOError -> Bool
isResourceVanishedError = IOErrorType -> Bool
isResourceVanishedErrorType forall b c a. (b -> c) -> (a -> b) -> a -> c
. IOError -> IOErrorType
ioeGetErrorType
alreadyExistsErrorType :: IOErrorType
alreadyExistsErrorType :: IOErrorType
alreadyExistsErrorType = IOErrorType
AlreadyExists
doesNotExistErrorType :: IOErrorType
doesNotExistErrorType :: IOErrorType
doesNotExistErrorType = IOErrorType
NoSuchThing
alreadyInUseErrorType :: IOErrorType
alreadyInUseErrorType :: IOErrorType
alreadyInUseErrorType = IOErrorType
ResourceBusy
fullErrorType :: IOErrorType
fullErrorType :: IOErrorType
fullErrorType = IOErrorType
ResourceExhausted
eofErrorType :: IOErrorType
eofErrorType :: IOErrorType
eofErrorType = IOErrorType
EOF
illegalOperationErrorType :: IOErrorType
illegalOperationErrorType :: IOErrorType
illegalOperationErrorType = IOErrorType
IllegalOperation
permissionErrorType :: IOErrorType
permissionErrorType :: IOErrorType
permissionErrorType = IOErrorType
PermissionDenied
userErrorType :: IOErrorType
userErrorType :: IOErrorType
userErrorType = IOErrorType
UserError
resourceVanishedErrorType :: IOErrorType
resourceVanishedErrorType :: IOErrorType
resourceVanishedErrorType = IOErrorType
ResourceVanished
isAlreadyExistsErrorType :: IOErrorType -> Bool
isAlreadyExistsErrorType :: IOErrorType -> Bool
isAlreadyExistsErrorType IOErrorType
AlreadyExists = Bool
True
isAlreadyExistsErrorType IOErrorType
_ = Bool
False
isDoesNotExistErrorType :: IOErrorType -> Bool
isDoesNotExistErrorType :: IOErrorType -> Bool
isDoesNotExistErrorType IOErrorType
NoSuchThing = Bool
True
isDoesNotExistErrorType IOErrorType
_ = Bool
False
isAlreadyInUseErrorType :: IOErrorType -> Bool
isAlreadyInUseErrorType :: IOErrorType -> Bool
isAlreadyInUseErrorType IOErrorType
ResourceBusy = Bool
True
isAlreadyInUseErrorType IOErrorType
_ = Bool
False
isFullErrorType :: IOErrorType -> Bool
isFullErrorType :: IOErrorType -> Bool
isFullErrorType IOErrorType
ResourceExhausted = Bool
True
isFullErrorType IOErrorType
_ = Bool
False
isEOFErrorType :: IOErrorType -> Bool
isEOFErrorType :: IOErrorType -> Bool
isEOFErrorType IOErrorType
EOF = Bool
True
isEOFErrorType IOErrorType
_ = Bool
False
isIllegalOperationErrorType :: IOErrorType -> Bool
isIllegalOperationErrorType :: IOErrorType -> Bool
isIllegalOperationErrorType IOErrorType
IllegalOperation = Bool
True
isIllegalOperationErrorType IOErrorType
_ = Bool
False
isPermissionErrorType :: IOErrorType -> Bool
isPermissionErrorType :: IOErrorType -> Bool
isPermissionErrorType IOErrorType
PermissionDenied = Bool
True
isPermissionErrorType IOErrorType
_ = Bool
False
isUserErrorType :: IOErrorType -> Bool
isUserErrorType :: IOErrorType -> Bool
isUserErrorType IOErrorType
UserError = Bool
True
isUserErrorType IOErrorType
_ = Bool
False
isResourceVanishedErrorType :: IOErrorType -> Bool
isResourceVanishedErrorType :: IOErrorType -> Bool
isResourceVanishedErrorType IOErrorType
ResourceVanished = Bool
True
isResourceVanishedErrorType IOErrorType
_ = Bool
False
ioeGetErrorType :: IOError -> IOErrorType
ioeGetErrorString :: IOError -> String
ioeGetLocation :: IOError -> String
ioeGetHandle :: IOError -> Maybe Handle
ioeGetFileName :: IOError -> Maybe FilePath
ioeGetErrorType :: IOError -> IOErrorType
ioeGetErrorType IOError
ioe = IOError -> IOErrorType
ioe_type IOError
ioe
ioeGetErrorString :: IOError -> String
ioeGetErrorString IOError
ioe
| IOErrorType -> Bool
isUserErrorType (IOError -> IOErrorType
ioe_type IOError
ioe) = IOError -> String
ioe_description IOError
ioe
| Bool
otherwise = forall a. Show a => a -> String
show (IOError -> IOErrorType
ioe_type IOError
ioe)
ioeGetLocation :: IOError -> String
ioeGetLocation IOError
ioe = IOError -> String
ioe_location IOError
ioe
ioeGetHandle :: IOError -> Maybe Handle
ioeGetHandle IOError
ioe = IOError -> Maybe Handle
ioe_handle IOError
ioe
ioeGetFileName :: IOError -> Maybe String
ioeGetFileName IOError
ioe = IOError -> Maybe String
ioe_filename IOError
ioe
ioeSetErrorType :: IOError -> IOErrorType -> IOError
ioeSetErrorString :: IOError -> String -> IOError
ioeSetLocation :: IOError -> String -> IOError
ioeSetHandle :: IOError -> Handle -> IOError
ioeSetFileName :: IOError -> FilePath -> IOError
ioeSetErrorType :: IOError -> IOErrorType -> IOError
ioeSetErrorType IOError
ioe IOErrorType
errtype = IOError
ioe{ ioe_type :: IOErrorType
ioe_type = IOErrorType
errtype }
ioeSetErrorString :: IOError -> String -> IOError
ioeSetErrorString IOError
ioe String
str = IOError
ioe{ ioe_description :: String
ioe_description = String
str }
ioeSetLocation :: IOError -> String -> IOError
ioeSetLocation IOError
ioe String
str = IOError
ioe{ ioe_location :: String
ioe_location = String
str }
ioeSetHandle :: IOError -> Handle -> IOError
ioeSetHandle IOError
ioe Handle
hdl = IOError
ioe{ ioe_handle :: Maybe Handle
ioe_handle = forall a. a -> Maybe a
Just Handle
hdl }
ioeSetFileName :: IOError -> String -> IOError
ioeSetFileName IOError
ioe String
filename = IOError
ioe{ ioe_filename :: Maybe String
ioe_filename = forall a. a -> Maybe a
Just String
filename }
modifyIOError :: (IOError -> IOError) -> IO a -> IO a
modifyIOError :: forall a. (IOError -> IOError) -> IO a -> IO a
modifyIOError IOError -> IOError
f IO a
io = forall e a. Exception e => IO a -> (e -> IO a) -> IO a
catch IO a
io (\IOError
e -> forall a. IOError -> IO a
ioError (IOError -> IOError
f IOError
e))
annotateIOError :: IOError
-> String
-> Maybe Handle
-> Maybe FilePath
-> IOError
annotateIOError :: IOError -> String -> Maybe Handle -> Maybe String -> IOError
annotateIOError IOError
ioe String
loc Maybe Handle
hdl Maybe String
path =
IOError
ioe{ ioe_handle :: Maybe Handle
ioe_handle = Maybe Handle
hdl forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` IOError -> Maybe Handle
ioe_handle IOError
ioe,
ioe_location :: String
ioe_location = String
loc, ioe_filename :: Maybe String
ioe_filename = Maybe String
path forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` IOError -> Maybe String
ioe_filename IOError
ioe }
catchIOError :: IO a -> (IOError -> IO a) -> IO a
catchIOError :: forall a. IO a -> (IOError -> IO a) -> IO a
catchIOError = forall e a. Exception e => IO a -> (e -> IO a) -> IO a
catch