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 )
30 data IOError13 = AlreadyExists String
31 | HardwareFault String
32 | IllegalOperation String
33 | InappropriateType String
35 | InvalidArgument String
38 | PermissionDenied String
39 | ProtocolError String
41 | ResourceExhausted String
42 | ResourceVanished String
45 | UnsatisfiedConstraints String
46 | UnsupportedOperation String
49 -- not really OK: deriving (Text)
51 instance Text IOError13 where -- NB: not interested in reading
52 readsPrec p = error "readsPrec: IOError13"
54 showsPrec p (AlreadyExists s) = show2 "AlreadyExists: " s
55 showsPrec p (HardwareFault s) = show2 "HardwareFault: " s
56 showsPrec p (IllegalOperation s) = show2 "IllegalOperation: " s
57 showsPrec p (InappropriateType s) = show2 "InappropriateType: " s
58 showsPrec p (Interrupted s) = show2 "Interrupted: " s
59 showsPrec p (InvalidArgument s) = show2 "InvalidArgument: " s
60 showsPrec p (NoSuchThing s) = show2 "NoSuchThing: " s
61 showsPrec p (OtherError13 s) = show2 "OtherError13: " s
62 showsPrec p (PermissionDenied s) = show2 "PermissionDenied: " s
63 showsPrec p (ProtocolError s) = show2 "ProtocolError: " s
64 showsPrec p (ResourceBusy s) = show2 "ResourceBusy: " s
65 showsPrec p (ResourceExhausted s) = show2 "ResourceExhausted: " s
66 showsPrec p (ResourceVanished s) = show2 "ResourceVanished: " s
67 showsPrec p (SystemError s) = show2 "SystemError: " s
68 showsPrec p (TimeExpired s) = show2 "TimeExpired: " s
69 showsPrec p (UnsatisfiedConstraints s) = show2 "UnsatisfiedConstraints: " s
70 showsPrec p (UnsupportedOperation s)= show2 "UnsupportedOperation: " s
71 showsPrec p (UserError s) = showString s
72 showsPrec p EOF = showString "EOF"
74 readList = _readList (readsPrec 0)
75 showList = _showList (showsPrec 0)
77 show2 x y = showString x . showString y
79 _constructError :: PrimIO IOError13
81 _casm_ ``%r = ghc_errtype;'' `thenPrimIO` \ (I# errtype#) ->
82 _casm_ ``%r = ghc_errstr;'' `thenPrimIO` \ str ->
84 msg = _unpackPS (_packCString str)
86 returnPrimIO (case errtype# of
87 ERR_ALREADYEXISTS# -> AlreadyExists msg
88 ERR_HARDWAREFAULT# -> HardwareFault msg
89 ERR_ILLEGALOPERATION# -> IllegalOperation msg
90 ERR_INAPPROPRIATETYPE# -> InappropriateType msg
91 ERR_INTERRUPTED# -> Interrupted msg
92 ERR_INVALIDARGUMENT# -> InvalidArgument msg
93 ERR_NOSUCHTHING# -> NoSuchThing msg
94 ERR_OTHERERROR# -> OtherError13 msg
95 ERR_PERMISSIONDENIED# -> PermissionDenied msg
96 ERR_PROTOCOLERROR# -> ProtocolError msg
97 ERR_RESOURCEBUSY# -> ResourceBusy msg
98 ERR_RESOURCEEXHAUSTED# -> ResourceExhausted msg
99 ERR_RESOURCEVANISHED# -> ResourceVanished msg
100 ERR_SYSTEMERROR# -> SystemError msg
101 ERR_TIMEEXPIRED# -> TimeExpired msg
102 ERR_UNSATISFIEDCONSTRAINTS# -> UnsatisfiedConstraints msg
103 ERR_UNSUPPORTEDOPERATION# -> UnsupportedOperation msg
105 _ -> OtherError13 "bad error construct"
109 The $String$ part of an $IOError13$ is platform-dependent. However, to
110 provide a uniform mechanism for distinguishing among errors within
111 these broad categories, each platform-specific standard shall specify
112 the exact strings to be used for particular errors. For errors not
113 explicitly mentioned in the standard, any descriptive string may be