1 ;;;; SBCL-specific parts of the condition system, i.e. parts which
2 ;;;; don't duplicate/clobber functionality already provided by the
3 ;;;; cross-compilation host Common Lisp
5 ;;;; This software is part of the SBCL system. See the README file for
8 ;;;; This software is derived from the CMU CL system, which was
9 ;;;; written at Carnegie Mellon University and released into the
10 ;;;; public domain. The software is in the public domain and is
11 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
12 ;;;; files for more information.
14 (in-package "SB!KERNEL")
16 ;;; not sure this is the right place, but where else?
17 (defun style-warn (datum &rest arguments
)
18 (/noshow0
"entering STYLE-WARN")
19 (/noshow datum arguments
)
22 (warn 'simple-style-warning
24 :format-arguments arguments
))
25 ;; Maybe FIXME: check that the DATUM is a STYLE-WARNING or a
26 ;; specifier for a subtype of STYLE-WARNING? (I had trouble
27 ;; getting through cold-init with that check enabled, though.)
29 (apply #'warn datum arguments
)))
31 ;;; a utility for SIGNAL, ERROR, CERROR, WARN, COMPILER-NOTIFY and
32 ;;; INVOKE-DEBUGGER: Parse the hairy argument conventions into a
33 ;;; single argument that's directly usable by all the other routines.
34 (defun coerce-to-condition (datum arguments default-type fun-name
)
35 (cond ((typep datum
'condition
)
36 (when (and arguments
(not (eq fun-name
'cerror
)))
37 (cerror "Ignore the additional arguments."
41 :format-control
"You may not supply additional arguments ~
42 when giving ~S to ~S."
43 :format-arguments
(list datum fun-name
)))
45 ((symbolp datum
) ; roughly, (SUBTYPEP DATUM 'CONDITION)
46 (apply #'make-condition datum arguments
))
47 ((or (stringp datum
) (functionp datum
))
48 (make-condition default-type
50 :format-arguments arguments
))
52 (error 'simple-type-error
54 :expected-type
'(or symbol string function
)
55 :format-control
"Condition designator ~s is not of type ~s."
56 :format-arguments
(list datum
57 '(or symbol string function
))))))
59 (define-condition layout-invalid
(type-error)
62 (lambda (condition stream
)
64 "~@<invalid structure layout: ~
65 ~2I~_A test for class ~4I~_~S ~
66 ~2I~_was passed the obsolete instance ~4I~_~S~:>"
67 (classoid-proper-name (type-error-expected-type condition
))
68 (type-error-datum condition
)))))
70 (define-condition case-failure
(type-error)
71 ((name :reader case-failure-name
:initarg
:name
)
72 (possibilities :reader case-failure-possibilities
:initarg
:possibilities
))
74 (lambda (condition stream
)
75 (let ((*print-escape
* t
))
76 (format stream
"~@<~S fell through ~S expression.~@[ ~
77 ~:_Wanted one of (~/pprint-fill/).~]~:>"
78 (type-error-datum condition
)
79 (case-failure-name condition
)
80 (case-failure-possibilities condition
))))))
82 (define-condition compiled-program-error
(program-error)
83 ((message :initarg
:message
:reader program-error-message
)
84 (source :initarg
:source
:reader program-error-source
))
85 (:report
(lambda (condition stream
)
86 (format stream
"Execution of a form compiled with errors.~%~
88 Compile-time error:~% ~A"
89 (program-error-source condition
)
90 (program-error-message condition
)))))
92 (define-condition interpreted-program-error
93 (program-error encapsulated-condition
)
94 ;; Unlike COMPILED-PROGRAM-ERROR, we don't need to dump these, so
95 ;; storing the original condition and form is OK.
96 ((form :initarg
:form
:reader program-error-form
))
97 (:report
(lambda (condition stream
)
98 (format stream
"~&Evaluation of~% ~S~%~
100 (program-error-form condition
)
101 (encapsulated-condition condition
)))))
103 (define-condition simple-control-error
(simple-condition control-error
) ())
104 (define-condition simple-file-error
(simple-condition file-error
) ())
105 (define-condition simple-program-error
(simple-condition program-error
) ())
106 (define-condition simple-stream-error
(simple-condition stream-error
) ())
107 (define-condition simple-parse-error
(simple-condition parse-error
) ())
109 (define-condition character-coding-error
(error)
110 ((external-format :initarg
:external-format
:reader character-coding-error-external-format
)))
111 (define-condition character-encoding-error
(character-coding-error)
112 ((code :initarg
:code
:reader character-encoding-error-code
)))
113 (define-condition character-decoding-error
(character-coding-error)
114 ((octets :initarg
:octets
:reader character-decoding-error-octets
)))
115 (define-condition stream-encoding-error
(stream-error character-encoding-error
)
119 (let ((stream (stream-error-stream c
))
120 (code (character-encoding-error-code c
)))
121 (format s
"~@<~S stream encoding error on ~S: ~2I~_~
122 the character with code ~D cannot be encoded.~@:>"
123 (character-coding-error-external-format c
)
126 (define-condition stream-decoding-error
(stream-error character-decoding-error
)
130 (let ((stream (stream-error-stream c
))
131 (octets (character-decoding-error-octets c
)))
132 (format s
"~@<~S stream decoding error on ~S: ~2I~_~
133 the octet sequence ~S cannot be decoded.~@:>"
134 (character-coding-error-external-format c
)
138 (define-condition c-string-encoding-error
(character-encoding-error)
142 (format s
"~@<~S c-string encoding error: ~2I~_~
143 the character with code ~D cannot be encoded.~@:>"
144 (character-coding-error-external-format c
)
145 (character-encoding-error-code c
)))))
147 (define-condition c-string-decoding-error
(character-decoding-error)
151 (format s
"~@<~S c-string decoding error: ~2I~_~
152 the octet sequence ~S cannot be decoded.~@:>"
153 (character-coding-error-external-format c
)
154 (character-decoding-error-octets c
)))))
156 (define-condition control-stack-exhausted
(storage-condition)
159 (lambda (condition stream
)
160 (declare (ignore condition
))
162 ;; no pretty-printing, because that would use a lot of stack.
163 "Control stack exhausted (no more space for function call frames).
164 This is probably due to heavily nested or infinitely recursive function
165 calls, or a tail call that SBCL cannot or has not optimized away.
167 PROCEED WITH CAUTION."))))
169 (define-condition binding-stack-exhausted
(storage-condition)
172 (lambda (condition stream
)
173 (declare (ignore condition
))
175 ;; no pretty-printing, because that would use a lot of stack.
176 "Binding stack exhausted.
178 PROCEED WITH CAUTION."))))
180 (define-condition alien-stack-exhausted
(storage-condition)
183 (lambda (condition stream
)
184 (declare (ignore condition
))
186 ;; no pretty-printing, because that would use a lot of stack.
187 "Alien stack exhausted.
189 PROCEED WITH CAUTION."))))
191 (define-condition heap-exhausted-error
(storage-condition)
194 (lambda (condition stream
)
195 (declare (ignore condition
))
196 (declare (special *heap-exhausted-error-available-bytes
*
197 *heap-exhausted-error-requested-bytes
*))
198 ;; See comments in interr.lisp -- there is a method to this madness.
199 (if (and (boundp '*heap-exhausted-error-available-bytes
*)
200 (boundp '*heap-exhausted-error-requested-bytes
*))
202 ;; no pretty-printing, because that will use a lot of heap.
203 "Heap exhausted (no more space for allocation).
204 ~D bytes available, ~D requested.
206 PROCEED WITH CAUTION."
207 *heap-exhausted-error-available-bytes
*
208 *heap-exhausted-error-requested-bytes
*)
210 "A ~S condition without bindings for heap statistics. (If
211 you did not expect to see this message, please report it."
212 'heap-exhausted-error
)))))
214 (define-condition system-condition
(condition)
215 ((address :initarg
:address
:reader system-condition-address
:initform nil
)
216 (context :initarg
:context
:reader system-condition-context
:initform nil
)))
218 (define-condition memory-fault-error
(system-condition error
) ()
220 (lambda (condition stream
)
221 (format stream
"Unhandled memory fault at #x~X."
222 (system-condition-address condition
)))))
224 (define-condition breakpoint-error
(system-condition error
) ()
226 (lambda (condition stream
)
227 (format stream
"Unhandled breakpoint/trap at #x~X."
228 (system-condition-address condition
)))))
230 (define-condition interactive-interrupt
(system-condition serious-condition
) ()
232 (lambda (condition stream
)
233 (format stream
"Interactive interrupt at #x~X."
234 (system-condition-address condition
)))))