Remove CError.throwCError. Export the new function errnoToIOError.
Add a missing colon in a string inside IOException formed from
the error-specific part and optional filename. The IOException
representation has not changed yet, but IMHO the filename should
be kept separate.
Correctly handle user errors in IO.ioeGet* functions like other
IO errors.
Let fail :: String -> IO a throw a user error instead of invoking error
(Haskell98 is ambiguous about that and IMHO it should be this way;
this is also what nhc does).
% ------------------------------------------------------------------------------
% ------------------------------------------------------------------------------
-% $Id: PrelHandle.lhs,v 1.63 2000/11/07 10:42:56 simonmar Exp $
+% $Id: PrelHandle.lhs,v 1.64 2001/01/10 16:28:15 qrczak Exp $
%
% (c) The AQUA Project, Glasgow University, 1994-2000
%
%
% (c) The AQUA Project, Glasgow University, 1994-2000
%
import PrelAddr ( Addr, nullAddr )
import PrelByteArr ( ByteArray(..) )
import PrelRead ( Read )
import PrelAddr ( Addr, nullAddr )
import PrelByteArr ( ByteArray(..) )
import PrelRead ( Read )
-import PrelList ( span )
+import PrelList ( break )
import PrelIOBase
import PrelMaybe ( Maybe(..) )
import PrelException
import PrelIOBase
import PrelMaybe ( Maybe(..) )
import PrelException
ioeGetErrorString :: IOError -> String
ioeGetHandle :: IOError -> Maybe Handle
ioeGetErrorString :: IOError -> String
ioeGetHandle :: IOError -> Maybe Handle
-ioeGetHandle (IOException (IOError h _ _ _)) = h
-ioeGetHandle _ = error "IO.ioeGetHandle: not an IO error"
+ioeGetHandle (IOException (IOError h _ _ _)) = h
+ioeGetHandle (UserError _) = Nothing
+ioeGetHandle _ = error "IO.ioeGetHandle: not an IO error"
ioeGetErrorString (IOException (IOError _ iot _ str)) =
ioeGetErrorString (IOException (IOError _ iot _ str)) =
- case iot of
- EOF -> "end of file"
- _ -> str
-ioeGetErrorString _ = error "IO.ioeGetErrorString: not an IO error"
+ case iot of
+ EOF -> "end of file"
+ _ -> str
+ioeGetErrorString (UserError str) = str
+ioeGetErrorString _ = error "IO.ioeGetErrorString: not an IO error"
ioeGetFileName (IOException (IOError _ _ _ str)) =
ioeGetFileName (IOException (IOError _ _ _ str)) =
- case span (/=':') str of
- (_,[]) -> Nothing
- (fs,_) -> Just fs
-ioeGetFileName _ = error "IO.ioeGetFileName: not an IO error"
+ case break (== ':') str of
+ (_, []) -> Nothing
+ (_, _:' ':fs)-> Just fs
+ioeGetFileName (UserError _) = Nothing
+ioeGetFileName _ = error "IO.ioeGetFileName: not an IO error"
\end{code}
'Top-level' IO actions want to catch exceptions (e.g., forkIO and
\end{code}
'Top-level' IO actions want to catch exceptions (e.g., forkIO and
% ------------------------------------------------------------------------------
% ------------------------------------------------------------------------------
-% $Id: PrelIOBase.lhs,v 1.29 2000/11/07 10:42:56 simonmar Exp $
+% $Id: PrelIOBase.lhs,v 1.30 2001/01/10 16:28:15 qrczak Exp $
%
% (c) The University of Glasgow, 1994-2000
%
%
% (c) The University of Glasgow, 1994-2000
%
return x = returnIO x
m >>= k = bindIO m k
return x = returnIO x
m >>= k = bindIO m k
- fail s = error s -- not ioError?
+ fail s = ioError (userError s)
liftIO :: IO a -> State# RealWorld -> STret RealWorld a
liftIO (IO m) = \s -> case m s of (# s', r #) -> STret s' r
liftIO :: IO a -> State# RealWorld -> STret RealWorld a
liftIO (IO m) = \s -> case m s of (# s', r #) -> STret s' r
ERR_RESOURCEVANISHED -> ResourceVanished
ERR_SYSTEMERROR -> SystemError
ERR_TIMEEXPIRED -> TimeExpired
ERR_RESOURCEVANISHED -> ResourceVanished
ERR_SYSTEMERROR -> SystemError
ERR_TIMEEXPIRED -> TimeExpired
- ERR_UNSATISFIEDCONSTRAINTS -> UnsatisfiedConstraints
- ERR_UNSUPPORTEDOPERATION -> UnsupportedOperation
+ ERR_UNSATISFIEDCONSTRAINTS -> UnsatisfiedConstraints
+ ERR_UNSUPPORTEDOPERATION -> UnsupportedOperation
ERR_EOF -> EOF
_ -> OtherError
ERR_EOF -> EOF
_ -> OtherError
_ -> "") ++
(case reason of
Nothing -> ""
_ -> "") ++
(case reason of
Nothing -> ""
in
return (IOError Nothing iot call_site msg)
\end{code}
in
return (IOError Nothing iot call_site msg)
\end{code}