2 % (c) The AQUA Project, Glasgow University, 1994-1996
5 \section[PrelErr]{Module @PrelErr@}
7 The PrelErr module defines the code for the wired-in error functions,
8 which have a special type in the compiler (with "open tyvars").
10 We cannot define these functions in a module where they might be used
11 (e.g., PrelBase), because the magical wired-in type will get confused
12 with what the typechecker figures out.
15 {-# OPTIONS -fno-implicit-prelude #-}
19 , noMethodBindingError
20 , nonExhaustiveGuardsError
24 , recUpdError -- :: String -> a
26 , absentErr, parError -- :: a
29 , error -- :: String -> a
30 , assertError -- :: String -> Bool -> a -> a
34 import PrelIOBase ( IO(..) )
35 --import PrelHandle ( catch )
37 import PrelList ( span )
39 import PrelPack ( packString )
40 import PrelArr ( ByteArray(..) )
42 #ifndef __PARALLEL_HASKELL__
43 import PrelForeign ( StablePtr, deRefStablePtr )
46 ---------------------------------------------------------------
47 -- HACK: Magic unfoldings not implemented for unboxed lists
48 -- Need to define a "build" to avoid undefined symbol
49 -- in this module to avoid .hi proliferation.
51 build = error "GHCbase.build"
52 augment = error "GHCbase.augment"
53 --{-# GENERATE_SPECS build a #-}
54 --build :: ((a -> [a] -> [a]) -> [a] -> [a]) -> [a]
58 %*********************************************************
60 \subsection{Error-ish functions}
62 %*********************************************************
69 = case (errorIO# io) of
72 bottom = bottom -- Never evaluated
74 --ioError :: String -> a
75 --ioError s = error__ ``&IOErrorHdrHook'' s
77 -- error stops execution and displays an error message
79 error s = throw (ErrorCall s)
80 --error s = error__ ``&ErrorHdrHook'' s
82 -- This local variant of "error" calls PatErrorHdrHook instead of ErrorHdrHook,
83 -- but the former does exactly the same as the latter, so I nuked it.
86 -- Hmm..distinguishing between these two kinds of error is quite useful in the
87 -- compiler sources, printing out a more verbose msg in the case of patter
89 -- So I've reinstated patError to invoke its own message function hook again.
91 patError__ x = error__ ``&PatErrorHdrHook'' x
93 error__ :: Addr{-C function pointer to hook-} -> String -> a
96 #ifdef __PARALLEL_HASKELL__
98 (hFlush stdout) `catchException` (\ _ -> return ())
99 let bs@(ByteArray (_,len) _) = packString s
100 _ccall_ writeErrString__ msg_hdr bs len
101 _ccall_ stg_exit (1::Int)
105 (hFlush stdout) `catchException` (\ _ -> return ())
106 -- Note: there's potential for trouble here in a
107 -- a concurrent setting if an error is flagged after the
108 -- lock on the stdout handle. (I don't see a possibility
109 -- of this occurring with the current impl, but still.)
110 let bs@(ByteArray (_,len) _) = packString s
111 _ccall_ writeErrString__ msg_hdr bs len
112 errorHandler <- _ccall_ getErrorHandler
113 if errorHandler == (-1::Int) then
114 _ccall_ stg_exit (1::Int)
116 osptr <- _casm_ ``%r = (StgStablePtr)(%0);'' errorHandler
117 _ccall_ decrementErrorCount
118 oact <- deRefStablePtr osptr
122 #endif {- !parallel -}
126 %*********************************************************
128 \subsection{Compiler generated errors + local utils}
130 %*********************************************************
132 Used for compiler-generated error message;
133 encoding saves bytes of string junk.
136 absentErr, parError, seqError :: a
138 absentErr = error "Oops! The program has entered an `absent' argument!\n"
139 parError = error "Oops! Entered GHCerr.parError (a GHC bug -- please report it!)\n"
140 seqError = error "Oops! Entered seqError (a GHC bug -- please report it!)\n"
146 , noMethodBindingError
147 , nonExhaustiveGuardsError
151 , recUpdError :: String -> a
153 noMethodBindingError s = throw (NoMethodError (untangle s "No instance nor default method for class operation"))
154 irrefutPatError s = throw (PatternMatchFail (untangle s "Irrefutable pattern failed for pattern"))
155 nonExhaustiveGuardsError s = throw (NonExhaustiveGuards (untangle s "Non-exhaustive guards in"))
156 patError s = throw (PatternMatchFail (untangle s "Non-exhaustive patterns in"))
157 recSelError s = throw (RecSelError (untangle s "Missing field in record selection:"))
158 recConError s = throw (RecConError (untangle s "Missing field in record construction:"))
159 recUpdError s = throw (RecUpdError (untangle s "Record to doesn't contain field(s) to be updated"))
162 assertError :: String -> Bool -> a -> a
163 assertError str pred v
165 | otherwise = error (untangle str "Assertion failed")
170 (untangle coded message) expects "coded" to be of the form
176 location message details
179 untangle coded message
187 = case (span not_bar coded) of { (location, rest) ->
189 ('|':details) -> (location, ' ' : details)