X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=System%2FIO%2FError.hs;h=55b9ca466925f1f305ca8cf0e74b77014f623822;hb=fb80d56c0b7617261c93a808e9001bbb25a7562e;hp=95fde8522a97ae6eeef09e4fad6e7327e2e51548;hpb=aaf764b3ad8b1816d68b5f27299eac125f08e1a5;p=ghc-base.git diff --git a/System/IO/Error.hs b/System/IO/Error.hs index 95fde85..55b9ca4 100644 --- a/System/IO/Error.hs +++ b/System/IO/Error.hs @@ -1,4 +1,4 @@ -{-# OPTIONS_GHC -fno-implicit-prelude #-} +{-# OPTIONS_GHC -XNoImplicitPrelude #-} ----------------------------------------------------------------------------- -- | @@ -17,20 +17,20 @@ module System.IO.Error ( -- * I\/O errors - IOError, -- = IOException + IOError, -- = IOException - userError, -- :: String -> IOError + userError, -- :: String -> IOError #ifndef __NHC__ - mkIOError, -- :: IOErrorType -> String -> Maybe Handle - -- -> Maybe FilePath -> IOError + mkIOError, -- :: IOErrorType -> String -> Maybe Handle + -- -> Maybe FilePath -> IOError - annotateIOError, -- :: IOError -> String -> Maybe Handle - -- -> Maybe FilePath -> IOError + annotateIOError, -- :: IOError -> String -> Maybe Handle + -- -> Maybe FilePath -> IOError #endif -- ** Classifying I\/O errors - isAlreadyExistsError, -- :: IOError -> Bool + isAlreadyExistsError, -- :: IOError -> Bool isDoesNotExistError, isAlreadyInUseError, isFullError, @@ -41,23 +41,25 @@ module System.IO.Error ( -- ** Attributes of I\/O errors #ifndef __NHC__ - ioeGetErrorType, -- :: IOError -> IOErrorType + ioeGetErrorType, -- :: IOError -> IOErrorType + ioeGetLocation, -- :: IOError -> String #endif - ioeGetErrorString, -- :: IOError -> String - ioeGetHandle, -- :: IOError -> Maybe Handle - ioeGetFileName, -- :: IOError -> Maybe FilePath + ioeGetErrorString, -- :: IOError -> String + ioeGetHandle, -- :: IOError -> Maybe Handle + ioeGetFileName, -- :: IOError -> Maybe FilePath #ifndef __NHC__ - ioeSetErrorType, -- :: IOError -> IOErrorType -> IOError - ioeSetErrorString, -- :: IOError -> String -> IOError - ioeSetHandle, -- :: IOError -> Handle -> IOError - ioeSetFileName, -- :: IOError -> FilePath -> IOError + ioeSetErrorType, -- :: IOError -> IOErrorType -> IOError + ioeSetErrorString, -- :: IOError -> String -> IOError + ioeSetLocation, -- :: IOError -> String -> IOError + ioeSetHandle, -- :: IOError -> Handle -> IOError + ioeSetFileName, -- :: IOError -> FilePath -> IOError #endif -- * Types of I\/O error - IOErrorType, -- abstract + IOErrorType, -- abstract - alreadyExistsErrorType, -- :: IOErrorType + alreadyExistsErrorType, -- :: IOErrorType doesNotExistErrorType, alreadyInUseErrorType, fullErrorType, @@ -67,7 +69,7 @@ module System.IO.Error ( userErrorType, -- ** 'IOErrorType' predicates - isAlreadyExistsErrorType, -- :: IOErrorType -> Bool + isAlreadyExistsErrorType, -- :: IOErrorType -> Bool isDoesNotExistErrorType, isAlreadyInUseErrorType, isFullErrorType, @@ -78,23 +80,24 @@ module System.IO.Error ( -- * Throwing and catching I\/O errors - ioError, -- :: IOError -> IO a + ioError, -- :: IOError -> IO a - catch, -- :: IO a -> (IOError -> IO a) -> IO a - try, -- :: IO a -> IO (Either IOError a) + catch, -- :: IO a -> (IOError -> IO a) -> IO a + try, -- :: IO a -> IO (Either IOError a) #ifndef __NHC__ - modifyIOError, -- :: (IOError -> IOError) -> IO a -> IO a + modifyIOError, -- :: (IOError -> IOError) -> IO a -> IO a #endif ) where +import {-# SOURCE #-} Prelude (catch) + import Data.Either import Data.Maybe #ifdef __GLASGOW_HASKELL__ import GHC.Base import GHC.IOBase -import GHC.Exception import Text.Show #endif @@ -108,7 +111,7 @@ import IO , try , ioError , userError - , isAlreadyExistsError -- :: IOError -> Bool + , isAlreadyExistsError -- :: IOError -> Bool , isDoesNotExistError , isAlreadyInUseError , isFullError @@ -148,11 +151,11 @@ try f = catch (do r <- f mkIOError :: IOErrorType -> String -> Maybe Handle -> Maybe FilePath -> IOError mkIOError t location maybe_hdl maybe_filename = IOError{ ioe_type = t, - ioe_location = location, - ioe_description = "", - ioe_handle = maybe_hdl, - ioe_filename = maybe_filename - } + ioe_location = location, + ioe_description = "", + ioe_handle = maybe_hdl, + ioe_filename = maybe_filename + } #ifdef __NHC__ mkIOError EOF location maybe_hdl maybe_filename = EOFError location (fromJust maybe_hdl) @@ -226,8 +229,8 @@ isUserError = isUserErrorType . ioeGetErrorType #ifdef __NHC__ data IOErrorType = AlreadyExists | NoSuchThing | ResourceBusy - | ResourceExhausted | EOF | IllegalOperation - | PermissionDenied | UserError + | ResourceExhausted | EOF | IllegalOperation + | PermissionDenied | UserError #endif -- | I\/O error where the operation failed because one of its arguments @@ -264,8 +267,8 @@ permissionErrorType :: IOErrorType permissionErrorType = PermissionDenied -- | I\/O error that is programmer-defined. -userErrorType :: IOErrorType -userErrorType = UserError +userErrorType :: IOErrorType +userErrorType = UserError -- ----------------------------------------------------------------------------- -- IOErrorType predicates @@ -319,8 +322,9 @@ isUserErrorType _ = False -- Miscellaneous #if defined(__GLASGOW_HASKELL__) || defined(__HUGS__) -ioeGetErrorType :: IOError -> IOErrorType +ioeGetErrorType :: IOError -> IOErrorType ioeGetErrorString :: IOError -> String +ioeGetLocation :: IOError -> String ioeGetHandle :: IOError -> Maybe Handle ioeGetFileName :: IOError -> Maybe FilePath @@ -330,17 +334,21 @@ ioeGetErrorString ioe | isUserErrorType (ioe_type ioe) = ioe_description ioe | otherwise = show (ioe_type ioe) +ioeGetLocation ioe = ioe_location ioe + ioeGetHandle ioe = ioe_handle ioe ioeGetFileName ioe = ioe_filename ioe -ioeSetErrorType :: IOError -> IOErrorType -> IOError -ioeSetErrorString :: IOError -> String -> IOError -ioeSetHandle :: IOError -> Handle -> IOError -ioeSetFileName :: IOError -> FilePath -> IOError +ioeSetErrorType :: IOError -> IOErrorType -> IOError +ioeSetErrorString :: IOError -> String -> IOError +ioeSetLocation :: IOError -> String -> IOError +ioeSetHandle :: IOError -> Handle -> IOError +ioeSetFileName :: IOError -> FilePath -> IOError ioeSetErrorType ioe errtype = ioe{ ioe_type = errtype } ioeSetErrorString ioe str = ioe{ ioe_description = str } +ioeSetLocation ioe str = ioe{ ioe_location = str } ioeSetHandle ioe hdl = ioe{ ioe_handle = Just hdl } ioeSetFileName ioe filename = ioe{ ioe_filename = Just filename }