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 ;;; a utility for SIGNAL, ERROR, CERROR, WARN, COMPILER-NOTIFY and
17 ;;; INVOKE-DEBUGGER: Parse the hairy argument conventions into a
18 ;;; single argument that's directly usable by all the other routines.
19 (defun coerce-to-condition (datum default-type fun-name
&rest arguments
)
20 (declare (explicit-check)
21 (dynamic-extent arguments
))
22 (cond ((and (%instancep datum
)
23 (let ((layout (%instance-layout datum
)))
24 (logtest +condition-layout-flag
+ (layout-%flags layout
))
25 ;; An invalid layout will drop into the (MAKE-CONDITION) branch
26 ;; which rightly fails because ALLOCATE-CONDITION asserts that
27 ;; the first argument is a condition-designator, which it won't be.
28 (not (layout-invalid layout
))))
29 (when (and arguments
(not (eq fun-name
'cerror
)))
30 (cerror "Ignore the additional arguments."
32 :datum
(copy-list arguments
)
34 :format-control
"You may not supply additional arguments ~
35 when giving ~S to ~S."
36 :format-arguments
(list datum fun-name
)))
38 ((or (stringp datum
) (functionp datum
))
39 (make-condition default-type
41 :format-arguments
(copy-list arguments
)))
43 (apply #'make-condition datum arguments
))))
45 (define-condition layout-invalid
(type-error)
48 (lambda (condition stream
)
50 "~@<invalid structure layout: ~
51 ~2I~_A test for class ~4I~_~S ~
52 ~2I~_was passed the obsolete instance ~4I~_~S~:>"
53 (classoid-proper-name (type-error-expected-type condition
))
54 (type-error-datum condition
)))))
56 (define-condition case-failure
(type-error)
57 ((name :reader case-failure-name
:initarg
:name
)
58 (possibilities :reader case-failure-possibilities
:initarg
:possibilities
))
60 (lambda (condition stream
)
61 (let ((*print-escape
* t
))
62 (format stream
"~@<~S fell through ~S expression.~@[ ~
63 ~:_Wanted one of (~/pprint-fill/).~]~:>"
64 (type-error-datum condition
)
65 (case-failure-name condition
)
66 (case-failure-possibilities condition
))))))
68 (define-condition compiled-program-error
(program-error)
69 ((message :initarg
:message
:reader program-error-message
)
70 (source :initarg
:source
:reader program-error-source
))
71 (:report
(lambda (condition stream
)
72 (format stream
"Execution of a form compiled with errors.~%~
74 Compile-time error:~% ~A"
75 (program-error-source condition
)
76 (program-error-message condition
)))))
78 (define-condition interpreted-program-error
79 (program-error encapsulated-condition
)
80 ;; Unlike COMPILED-PROGRAM-ERROR, we don't need to dump these, so
81 ;; storing the original condition and form is OK.
82 ((form :initarg
:form
:reader program-error-form
))
83 (:report
(lambda (condition stream
)
84 (format stream
"~&Evaluation of~% ~S~%~
86 (program-error-form condition
)
87 (encapsulated-condition condition
)))))
89 (define-condition simple-control-error
(simple-condition control-error
) ())
90 (define-condition simple-file-error
(simple-condition file-error
) ())
91 (define-condition simple-program-error
(simple-condition program-error
) ())
92 (define-condition simple-stream-error
(simple-condition stream-error
) ())
93 (define-condition simple-parse-error
(simple-condition parse-error
) ())
95 (define-condition character-coding-error
(error)
96 ((external-format :initarg
:external-format
:reader character-coding-error-external-format
)))
97 (define-condition character-encoding-error
(character-coding-error)
98 ((code :initarg
:code
:reader character-encoding-error-code
)))
99 (define-condition character-decoding-error
(character-coding-error)
100 ((octets :initarg
:octets
:reader character-decoding-error-octets
)))
101 (define-condition stream-encoding-error
(stream-error character-encoding-error
)
105 (let ((stream (stream-error-stream c
))
106 (code (character-encoding-error-code c
)))
107 (format s
"~@<~S stream encoding error on ~S: ~2I~_~
108 the character with code ~D cannot be encoded.~@:>"
109 (character-coding-error-external-format c
)
112 (define-condition stream-decoding-error
(stream-error character-decoding-error
)
116 (let ((stream (stream-error-stream c
))
117 (octets (character-decoding-error-octets c
)))
118 (format s
"~@<~S stream decoding error on ~S: ~2I~_~
119 the octet sequence ~S cannot be decoded.~@:>"
120 (character-coding-error-external-format c
)
124 (define-condition c-string-encoding-error
(character-encoding-error)
128 (format s
"~@<~S c-string encoding error: ~2I~_~
129 the character with code ~D cannot be encoded.~@:>"
130 (character-coding-error-external-format c
)
131 (character-encoding-error-code c
)))))
133 (define-condition c-string-decoding-error
(character-decoding-error)
137 (format s
"~@<~S c-string decoding error: ~2I~_~
138 the octet sequence ~S cannot be decoded.~@:>"
139 (character-coding-error-external-format c
)
140 (character-decoding-error-octets c
)))))
142 (define-condition control-stack-exhausted
(storage-condition)
145 (lambda (condition stream
)
146 (declare (ignore condition
))
148 ;; no pretty-printing, because that would use a lot of stack.
149 "Control stack exhausted (no more space for function call frames).
150 This is probably due to heavily nested or infinitely recursive function
151 calls, or a tail call that SBCL cannot or has not optimized away.
153 PROCEED WITH CAUTION."))))
155 (define-condition binding-stack-exhausted
(storage-condition)
158 (lambda (condition stream
)
159 (declare (ignore condition
))
161 ;; no pretty-printing, because that would use a lot of stack.
162 "Binding stack exhausted.
164 PROCEED WITH CAUTION."))))
166 (define-condition alien-stack-exhausted
(storage-condition)
169 (lambda (condition stream
)
170 (declare (ignore condition
))
172 ;; no pretty-printing, because that would use a lot of stack.
173 "Alien stack exhausted.
175 PROCEED WITH CAUTION."))))
177 (define-condition heap-exhausted-error
(storage-condition)
180 (lambda (condition stream
)
181 (declare (ignore condition
))
182 (declare (special *heap-exhausted-error-available-bytes
*
183 *heap-exhausted-error-requested-bytes
*))
184 ;; See comments in interr.lisp -- there is a method to this madness.
185 (if (and (boundp '*heap-exhausted-error-available-bytes
*)
186 (boundp '*heap-exhausted-error-requested-bytes
*))
188 ;; no pretty-printing, because that will use a lot of heap.
189 "Heap exhausted (no more space for allocation).
190 ~D bytes available, ~D requested.
192 PROCEED WITH CAUTION."
193 *heap-exhausted-error-available-bytes
*
194 *heap-exhausted-error-requested-bytes
*)
196 "A ~S condition without bindings for heap statistics. (If
197 you did not expect to see this message, please report it."
198 'heap-exhausted-error
)))))
200 (define-condition system-condition
(condition)
201 ((address :initarg
:address
:reader system-condition-address
:initform nil
)
202 (context :initarg
:context
:reader system-condition-context
:initform nil
)))
204 (define-condition memory-fault-error
(system-condition error
) ()
206 (lambda (condition stream
)
207 (format stream
"Unhandled memory fault at #x~X."
208 (system-condition-address condition
)))))
210 (define-condition breakpoint-error
(system-condition error
) ()
212 (lambda (condition stream
)
213 (format stream
"Unhandled breakpoint/trap at #x~X."
214 (system-condition-address condition
)))))
216 (define-condition interactive-interrupt
(system-condition serious-condition
) ()
218 (lambda (condition stream
)
219 (format stream
"Interactive interrupt at #x~X."
220 (system-condition-address condition
)))))