2 % (c) The GRASP/AQUA Project, Glasgow University, 1994
4 \section[PrelIOErr]{I/O Errors}
6 Haskell 1.2 does not provide standard error values for I/O errors.
7 This is unacceptable for portable implementations which indulge in
8 non-trivial I/O. The $IOError$ type has therefore been extended from
9 Haskell 1.2, and possible error values have been identified for all
15 module PreludeIOError (IOError13(..), _constructError) where
24 import Prel ( (.), not )
28 data IOError13 = AlreadyExists String
29 | HardwareFault String
30 | IllegalOperation String
31 | InappropriateType String
33 | InvalidArgument String
36 | PermissionDenied String
37 | ProtocolError String
39 | ResourceExhausted String
40 | ResourceVanished String
43 | UnsatisfiedConstraints String
44 | UnsupportedOperation String
47 -- not really OK: deriving (Text)
49 instance Text IOError13 where -- NB: not interested in reading
50 showsPrec p (AlreadyExists s) = show2 "AlreadyExists: " s
51 showsPrec p (HardwareFault s) = show2 "HardwareFault: " s
52 showsPrec p (IllegalOperation s) = show2 "IllegalOperation: " s
53 showsPrec p (InappropriateType s) = show2 "InappropriateType: " s
54 showsPrec p (Interrupted s) = show2 "Interrupted: " s
55 showsPrec p (InvalidArgument s) = show2 "InvalidArgument: " s
56 showsPrec p (NoSuchThing s) = show2 "NoSuchThing: " s
57 showsPrec p (OtherError13 s) = show2 "OtherError13: " s
58 showsPrec p (PermissionDenied s) = show2 "PermissionDenied: " s
59 showsPrec p (ProtocolError s) = show2 "ProtocolError: " s
60 showsPrec p (ResourceBusy s) = show2 "ResourceBusy: " s
61 showsPrec p (ResourceExhausted s) = show2 "ResourceExhausted: " s
62 showsPrec p (ResourceVanished s) = show2 "ResourceVanished: " s
63 showsPrec p (SystemError s) = show2 "SystemError: " s
64 showsPrec p (TimeExpired s) = show2 "TimeExpired: " s
65 showsPrec p (UnsatisfiedConstraints s) = show2 "UnsatisfiedConstraints: " s
66 showsPrec p (UnsupportedOperation s)= show2 "UnsupportedOperation: " s
67 showsPrec p (UserError s) = showString s
68 showsPrec p EOF = showString "EOF"
70 show2 x y = showString x . showString y
72 _constructError :: PrimIO IOError13
74 _casm_ ``%r = ghc_errtype;'' `thenPrimIO` \ (I# errtype#) ->
75 _casm_ ``%r = ghc_errstr;'' `thenPrimIO` \ str ->
77 msg = _unpackPS (_packCString str)
79 returnPrimIO (case errtype# of
80 ERR_ALREADYEXISTS# -> AlreadyExists msg
81 ERR_HARDWAREFAULT# -> HardwareFault msg
82 ERR_ILLEGALOPERATION# -> IllegalOperation msg
83 ERR_INAPPROPRIATETYPE# -> InappropriateType msg
84 ERR_INTERRUPTED# -> Interrupted msg
85 ERR_INVALIDARGUMENT# -> InvalidArgument msg
86 ERR_NOSUCHTHING# -> NoSuchThing msg
87 ERR_OTHERERROR# -> OtherError13 msg
88 ERR_PERMISSIONDENIED# -> PermissionDenied msg
89 ERR_PROTOCOLERROR# -> ProtocolError msg
90 ERR_RESOURCEBUSY# -> ResourceBusy msg
91 ERR_RESOURCEEXHAUSTED# -> ResourceExhausted msg
92 ERR_RESOURCEVANISHED# -> ResourceVanished msg
93 ERR_SYSTEMERROR# -> SystemError msg
94 ERR_TIMEEXPIRED# -> TimeExpired msg
95 ERR_UNSATISFIEDCONSTRAINTS# -> UnsatisfiedConstraints msg
96 ERR_UNSUPPORTEDOPERATION# -> UnsupportedOperation msg
98 _ -> OtherError13 "bad error construct"
102 The $String$ part of an $IOError13$ is platform-dependent. However, to
103 provide a uniform mechanism for distinguishing among errors within
104 these broad categories, each platform-specific standard shall specify
105 the exact strings to be used for particular errors. For errors not
106 explicitly mentioned in the standard, any descriptive string may be