Skip to content
Snippets Groups Projects
Commit e3501543 authored by sof's avatar sof
Browse files

[project @ 1998-05-05 10:31:14 by sof]

constructErrorAndFailWithInfo: new function for including files/paths that caused IO op to fail
parent 2c3d6429
No related merge requests found
...@@ -133,7 +133,7 @@ The path refers to an existing non-directory object. ...@@ -133,7 +133,7 @@ The path refers to an existing non-directory object.
createDirectory path = do createDirectory path = do
rc <- _ccall_ createDirectory path rc <- _ccall_ createDirectory path
if rc == 0 then return () else if rc == 0 then return () else
constructErrorAndFail "createDirectory" constructErrorAndFailWithInfo "createDirectory" path
\end{code} \end{code}
@removeDirectory dir@ removes an existing directory {\em dir}. The @removeDirectory dir@ removes an existing directory {\em dir}. The
...@@ -176,7 +176,7 @@ removeDirectory path = do ...@@ -176,7 +176,7 @@ removeDirectory path = do
if rc == 0 then if rc == 0 then
return () return ()
else else
constructErrorAndFail "removeDirectory" constructErrorAndFailWithInfo "removeDirectory" path
\end{code} \end{code}
@removeFile file@ removes the directory entry for an existing file @removeFile file@ removes the directory entry for an existing file
...@@ -213,7 +213,7 @@ removeFile path = do ...@@ -213,7 +213,7 @@ removeFile path = do
if rc == 0 then if rc == 0 then
return () return ()
else else
constructErrorAndFail "removeFile" constructErrorAndFailWithInfo "removeFile" path
\end{code} \end{code}
@renameDirectory old@ {\em new} changes the name of an existing @renameDirectory old@ {\em new} changes the name of an existing
...@@ -260,7 +260,7 @@ renameDirectory opath npath = do ...@@ -260,7 +260,7 @@ renameDirectory opath npath = do
if rc == 0 then if rc == 0 then
return () return ()
else else
constructErrorAndFail "renameDirectory" constructErrorAndFailWithInfo "renameDirectory" opath
\end{code} \end{code}
@renameFile old@ {\em new} changes the name of an existing file system @renameFile old@ {\em new} changes the name of an existing file system
...@@ -305,7 +305,7 @@ renameFile opath npath = do ...@@ -305,7 +305,7 @@ renameFile opath npath = do
if rc == 0 then if rc == 0 then
return () return ()
else else
constructErrorAndFail "renameFile" constructErrorAndFailWithInfo "renameFile" opath
\end{code} \end{code}
@getDirectoryContents dir@ returns a list of {\em all} entries @getDirectoryContents dir@ returns a list of {\em all} entries
...@@ -338,7 +338,7 @@ The path refers to an existing non-directory object. ...@@ -338,7 +338,7 @@ The path refers to an existing non-directory object.
getDirectoryContents path = do getDirectoryContents path = do
dir <- _ccall_ openDir__ path dir <- _ccall_ openDir__ path
if dir == ``NULL'' if dir == ``NULL''
then constructErrorAndFail "getDirectoryContents" then constructErrorAndFailWithInfo "getDirectoryContents" path
else loop dir else loop dir
where where
loop :: Addr -> IO [String] loop :: Addr -> IO [String]
...@@ -346,6 +346,8 @@ getDirectoryContents path = do ...@@ -346,6 +346,8 @@ getDirectoryContents path = do
dirent_ptr <- _ccall_ readDir__ dir dirent_ptr <- _ccall_ readDir__ dir
if (dirent_ptr::Addr) == ``NULL'' if (dirent_ptr::Addr) == ``NULL''
then do then do
-- readDir__ implicitly performs closedir() when the
-- end is reached.
return [] return []
else do else do
str <- _casm_ `` %r=(char*)((struct dirent*)%0)->d_name; '' dirent_ptr str <- _casm_ `` %r=(char*)((struct dirent*)%0)->d_name; '' dirent_ptr
...@@ -423,7 +425,7 @@ setCurrentDirectory path = do ...@@ -423,7 +425,7 @@ setCurrentDirectory path = do
rc <- _ccall_ setCurrentDirectory path rc <- _ccall_ setCurrentDirectory path
if rc == 0 if rc == 0
then return () then return ()
else constructErrorAndFail "setCurrentDirectory" else constructErrorAndFailWithInfo "setCurrentDirectory" path
\end{code} \end{code}
......
...@@ -206,15 +206,7 @@ openFileEx f m = do ...@@ -206,15 +206,7 @@ openFileEx f m = do
newHandle (htype ptr Nothing False) newHandle (htype ptr Nothing False)
#endif #endif
else do else do
ioError@(IOError hn iot msg) <- constructError "openFile" constructErrorAndFailWithInfo "openFile" f
let
improved_error -- a HACK, I guess
= case iot of
AlreadyExists -> IOError hn AlreadyExists (msg ++ ": " ++ f)
NoSuchThing -> IOError hn NoSuchThing (msg ++ ": " ++ f)
PermissionDenied -> IOError hn PermissionDenied (msg ++ ": " ++ f)
_ -> ioError
fail improved_error
where where
imo = case m of imo = case m of
BinaryMode imo -> imo BinaryMode imo -> imo
......
...@@ -20,7 +20,7 @@ import PrelMaybe ...@@ -20,7 +20,7 @@ import PrelMaybe
import PrelAddr import PrelAddr
import PrelPack ( unpackCString ) import PrelPack ( unpackCString )
import PrelBase import PrelBase
import PrelArr ( ByteArray(..), MutableVar(..) ) import PrelArr ( ByteArray(..), MutableVar )
import PrelGHC import PrelGHC
\end{code} \end{code}
...@@ -216,17 +216,17 @@ the exact strings to be used for particular errors. For errors not ...@@ -216,17 +216,17 @@ the exact strings to be used for particular errors. For errors not
explicitly mentioned in the standard, any descriptive string may be explicitly mentioned in the standard, any descriptive string may be
used. used.
\begin{change}
SOF & 4/96 & added argument to indicate function that flagged error
\end{change}
% Hmm..does these envs work?!...SOF
\begin{code} \begin{code}
constructErrorAndFail :: String -> IO a constructErrorAndFail :: String -> IO a
constructErrorAndFail call_site constructErrorAndFail call_site
= constructError call_site >>= \ io_error -> = constructError call_site >>= \ io_error ->
fail io_error fail io_error
constructErrorAndFailWithInfo :: String -> String -> IO a
constructErrorAndFailWithInfo call_site reason
= constructErrorMsg call_site (Just reason) >>= \ io_error ->
fail io_error
\end{code} \end{code}
This doesn't seem to be documented/spelled out anywhere, This doesn't seem to be documented/spelled out anywhere,
...@@ -243,7 +243,10 @@ information. ...@@ -243,7 +243,10 @@ information.
\begin{code} \begin{code}
constructError :: String -> IO IOError constructError :: String -> IO IOError
constructError call_site = constructError call_site = constructErrorMsg call_site Nothing
constructErrorMsg :: String -> Maybe String -> IO IOError
constructErrorMsg call_site reason =
_casm_ ``%r = ghc_errtype;'' >>= \ (I# errtype#) -> _casm_ ``%r = ghc_errtype;'' >>= \ (I# errtype#) ->
_casm_ ``%r = ghc_errstr;'' >>= \ str -> _casm_ ``%r = ghc_errstr;'' >>= \ str ->
let let
...@@ -271,9 +274,12 @@ constructError call_site = ...@@ -271,9 +274,12 @@ constructError call_site =
msg = msg =
call_site ++ ':' : ' ' : unpackCString str ++ call_site ++ ':' : ' ' : unpackCString str ++
case iot of (case iot of
OtherError -> "(error code: " ++ show (I# errtype#) ++ ")" OtherError -> "(error code: " ++ show (I# errtype#) ++ ")"
_ -> "" _ -> "") ++
(case reason of
Nothing -> ""
Just m -> ' ':m)
in in
return (IOError Nothing iot msg) return (IOError Nothing iot msg)
\end{code} \end{code}
......
...@@ -12,7 +12,7 @@ module System ( ...@@ -12,7 +12,7 @@ module System (
import Prelude import Prelude
import PrelAddr import PrelAddr
import PrelIOBase ( IOError(..), IOErrorType(..), constructErrorAndFail ) import PrelIOBase ( IOError(..), IOErrorType(..), constructErrorAndFailWithInfo )
import PrelArr ( indexAddrOffAddr ) import PrelArr ( indexAddrOffAddr )
import PrelPack ( unpackCString ) import PrelPack ( unpackCString )
...@@ -103,7 +103,7 @@ system cmd = do ...@@ -103,7 +103,7 @@ system cmd = do
status <- _ccall_ systemCmd cmd status <- _ccall_ systemCmd cmd
case status of case status of
0 -> return ExitSuccess 0 -> return ExitSuccess
-1 -> constructErrorAndFail "system" -1 -> constructErrorAndFailWithInfo "system" cmd
n -> return (ExitFailure n) n -> return (ExitFailure n)
\end{code} \end{code}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment