1 ;;;; stuff originally from CMU CL's error.lisp which can or should
2 ;;;; come late (mostly related to the CONDITION class itself)
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 ;;;; the CONDITION class
18 (/show0 "condition.lisp 20")
20 (eval-when (:compile-toplevel :load-toplevel :execute)
22 (/show0 "condition.lisp 24")
24 (def!struct (condition-classoid (:include slot-classoid)
25 (:constructor make-condition-classoid))
26 ;; list of CONDITION-SLOT structures for the direct slots of this
28 (slots nil :type list)
29 ;; list of CONDITION-SLOT structures for all of the effective class
30 ;; slots of this class
31 (class-slots nil :type list)
32 ;; report function or NIL
33 (report nil :type (or function null))
34 ;; list of alternating initargs and initforms
35 (default-initargs () :type list)
36 ;; class precedence list as a list of CLASS objects, with all
37 ;; non-CONDITION classes removed
39 ;; a list of all the effective instance allocation slots of this
40 ;; class that have a non-constant initform or default-initarg.
41 ;; Values for these slots must be computed in the dynamic
42 ;; environment of MAKE-CONDITION.
43 (hairy-slots nil :type list))
45 (/show0 "condition.lisp 49")
49 (!defstruct-with-alternate-metaclass condition
50 :slot-names (actual-initargs assigned-slots)
51 :boa-constructor %make-condition-object
52 :superclass-name instance
53 :metaclass-name condition-classoid
54 :metaclass-constructor make-condition-classoid
57 (defun make-condition-object (actual-initargs)
58 (%make-condition-object actual-initargs nil))
60 (defstruct (condition-slot (:copier nil))
61 (name (missing-arg) :type symbol)
62 ;; list of all applicable initargs
63 (initargs (missing-arg) :type list)
64 ;; names of reader and writer functions
65 (readers (missing-arg) :type list)
66 (writers (missing-arg) :type list)
67 ;; true if :INITFORM was specified
68 (initform-p (missing-arg) :type (member t nil))
69 ;; If this is a function, call it with no args. Otherwise, it's the
71 (initform (missing-arg) :type t)
72 ;; allocation of this slot, or NIL until defaulted
73 (allocation nil :type (member :instance :class nil))
74 ;; If ALLOCATION is :CLASS, this is a cons whose car holds the value.
75 (cell nil :type (or cons null)))
77 ;;; KLUDGE: It's not clear to me why CONDITION-CLASS has itself listed
78 ;;; in its CPL, while other classes derived from CONDITION-CLASS don't
79 ;;; have themselves listed in their CPLs. This behavior is inherited
80 ;;; from CMU CL, and didn't seem to be explained there, and I haven't
81 ;;; figured out whether it's right. -- WHN 19990612
82 (eval-when (:compile-toplevel :load-toplevel :execute)
83 (/show0 "condition.lisp 103")
84 (let ((condition-class (locally
85 ;; KLUDGE: There's a DEFTRANSFORM
86 ;; FIND-CLASSOID for constant class names
87 ;; which creates fast but
88 ;; non-cold-loadable, non-compact code. In
89 ;; this context, we'd rather have compact,
90 ;; cold-loadable code. -- WHN 19990928
91 (declare (notinline find-classoid))
92 (find-classoid 'condition))))
93 (setf (condition-classoid-cpl condition-class)
94 (list condition-class)))
95 (/show0 "condition.lisp 103"))
97 (setf (condition-classoid-report (locally
98 ;; KLUDGE: There's a DEFTRANSFORM
99 ;; FIND-CLASSOID for constant class
100 ;; names which creates fast but
101 ;; non-cold-loadable, non-compact
102 ;; code. In this context, we'd
103 ;; rather have compact,
104 ;; cold-loadable code. -- WHN
106 (declare (notinline find-classoid))
107 (find-classoid 'condition)))
108 (lambda (cond stream)
109 (format stream "Condition ~S was signalled." (type-of cond))))
111 (eval-when (:compile-toplevel :load-toplevel :execute)
113 (defun find-condition-layout (name parent-types)
114 (let* ((cpl (remove-duplicates
118 (condition-classoid-cpl
121 (cond-layout (info :type :compiler-layout 'condition))
122 (olayout (info :type :compiler-layout name))
123 ;; FIXME: Does this do the right thing in case of multiple
124 ;; inheritance? A quick look at DEFINE-CONDITION didn't make
125 ;; it obvious what ANSI intends to be done in the case of
126 ;; multiple inheritance, so it's not actually clear what the
129 (order-layout-inherits (concatenate 'simple-vector
130 (layout-inherits cond-layout)
131 (mapcar #'classoid-layout cpl)))))
133 (not (mismatch (layout-inherits olayout) new-inherits)))
135 (make-layout :classoid (make-undefined-classoid name)
136 :inherits new-inherits
138 :length (layout-length cond-layout)))))
142 ;;; FIXME: ANSI's definition of DEFINE-CONDITION says
143 ;;; Condition reporting is mediated through the PRINT-OBJECT method
144 ;;; for the condition type in question, with *PRINT-ESCAPE* always
145 ;;; being nil. Specifying (:REPORT REPORT-NAME) in the definition of
146 ;;; a condition type C is equivalent to:
147 ;;; (defmethod print-object ((x c) stream)
148 ;;; (if *print-escape* (call-next-method) (report-name x stream)))
149 ;;; The current code doesn't seem to quite match that.
150 (def!method print-object ((x condition) stream)
152 (print-unreadable-object (x stream :type t :identity t))
153 ;; KLUDGE: A comment from CMU CL here said
154 ;; 7/13/98 BUG? CPL is not sorted and results here depend on order of
155 ;; superclasses in define-condition call!
156 (dolist (class (condition-classoid-cpl (classoid-of x))
157 (error "no REPORT? shouldn't happen!"))
158 (let ((report (condition-classoid-report class)))
160 (return (funcall report x stream)))))))
162 ;;;; slots of CONDITION objects
164 (defvar *empty-condition-slot* '(empty))
166 (defun find-slot-default (class slot)
167 (let ((initargs (condition-slot-initargs slot))
168 (cpl (condition-classoid-cpl class)))
170 (let ((default-initargs (condition-classoid-default-initargs class)))
171 (dolist (initarg initargs)
172 (let ((val (getf default-initargs initarg *empty-condition-slot*)))
173 (unless (eq val *empty-condition-slot*)
174 (return-from find-slot-default
179 (if (condition-slot-initform-p slot)
180 (let ((initform (condition-slot-initform slot)))
181 (if (functionp initform)
184 (error "unbound condition slot: ~S" (condition-slot-name slot)))))
186 (defun find-condition-class-slot (condition-class slot-name)
188 (condition-classoid-cpl condition-class)
189 (error "There is no slot named ~S in ~S."
190 slot-name condition-class))
191 (dolist (slot (condition-classoid-slots sclass))
192 (when (eq (condition-slot-name slot) slot-name)
193 (return-from find-condition-class-slot slot)))))
195 (defun condition-writer-function (condition new-value name)
196 (dolist (cslot (condition-classoid-class-slots
197 (layout-classoid (%instance-layout condition)))
198 (setf (getf (condition-assigned-slots condition) name)
200 (when (eq (condition-slot-name cslot) name)
201 (return (setf (car (condition-slot-cell cslot)) new-value)))))
203 (defun condition-reader-function (condition name)
204 (let ((class (layout-classoid (%instance-layout condition))))
205 (dolist (cslot (condition-classoid-class-slots class))
206 (when (eq (condition-slot-name cslot) name)
207 (return-from condition-reader-function
208 (car (condition-slot-cell cslot)))))
209 (let ((val (getf (condition-assigned-slots condition) name
210 *empty-condition-slot*)))
211 (if (eq val *empty-condition-slot*)
212 (let ((actual-initargs (condition-actual-initargs condition))
213 (slot (find-condition-class-slot class name)))
215 (error "missing slot ~S of ~S" name condition))
216 (do ((initargs actual-initargs (cddr initargs)))
218 (setf (getf (condition-assigned-slots condition) name)
219 (find-slot-default class slot)))
220 (when (member (car initargs) (condition-slot-initargs slot))
221 (return-from condition-reader-function
222 (setf (getf (condition-assigned-slots condition)
229 (defun make-condition (thing &rest args)
231 "Make an instance of a condition object using the specified initargs."
232 ;; Note: ANSI specifies no exceptional situations in this function.
233 ;; signalling simple-type-error would not be wrong.
234 (let* ((thing (if (symbolp thing)
235 (find-classoid thing)
237 (class (typecase thing
238 (condition-classoid thing)
240 (error 'simple-type-error
242 :expected-type 'condition-class
243 :format-control "~S is not a condition class."
244 :format-arguments (list thing)))
246 (error 'simple-type-error
248 :expected-type 'condition-class
249 :format-control "bad thing for class argument:~% ~S"
250 :format-arguments (list thing)))))
251 (res (make-condition-object args)))
252 (setf (%instance-layout res) (classoid-layout class))
253 ;; Set any class slots with initargs present in this call.
254 (dolist (cslot (condition-classoid-class-slots class))
255 (dolist (initarg (condition-slot-initargs cslot))
256 (let ((val (getf args initarg *empty-condition-slot*)))
257 (unless (eq val *empty-condition-slot*)
258 (setf (car (condition-slot-cell cslot)) val)))))
259 ;; Default any slots with non-constant defaults now.
260 (dolist (hslot (condition-classoid-hairy-slots class))
261 (when (dolist (initarg (condition-slot-initargs hslot) t)
262 (unless (eq (getf args initarg *empty-condition-slot*)
263 *empty-condition-slot*)
265 (setf (getf (condition-assigned-slots res) (condition-slot-name hslot))
266 (find-slot-default class hslot))))
270 ;;;; DEFINE-CONDITION
272 (eval-when (:compile-toplevel :load-toplevel :execute)
273 (defun %compiler-define-condition (name direct-supers layout)
274 (multiple-value-bind (class old-layout)
275 (insured-find-classoid name
276 #'condition-classoid-p
277 #'make-condition-classoid)
278 (setf (layout-classoid layout) class)
279 (setf (classoid-direct-superclasses class)
280 (mapcar #'find-classoid direct-supers))
281 (cond ((not old-layout)
282 (register-layout layout))
283 ((not *type-system-initialized*)
284 (setf (layout-classoid old-layout) class)
285 (setq layout old-layout)
286 (unless (eq (classoid-layout class) layout)
287 (register-layout layout)))
288 ((redefine-layout-warning "current"
291 (layout-length layout)
292 (layout-inherits layout)
293 (layout-depthoid layout))
294 (register-layout layout :invalidate t))
295 ((not (classoid-layout class))
296 (register-layout layout)))
298 (setf (layout-info layout)
300 ;; KLUDGE: There's a FIND-CLASS DEFTRANSFORM for constant class
301 ;; names which creates fast but non-cold-loadable, non-compact
302 ;; code. In this context, we'd rather have compact, cold-loadable
303 ;; code. -- WHN 19990928
304 (declare (notinline find-classoid))
305 (layout-info (classoid-layout (find-classoid 'condition)))))
307 (setf (find-classoid name) class)
309 ;; Initialize CPL slot.
310 (setf (condition-classoid-cpl class)
311 (remove-if-not #'condition-classoid-p
312 (std-compute-class-precedence-list class))))
317 ;;; Compute the effective slots of CLASS, copying inherited slots and
318 ;;; destructively modifying direct slots.
320 ;;; FIXME: It'd be nice to explain why it's OK to destructively modify
321 ;;; direct slots. Presumably it follows from the semantics of
322 ;;; inheritance and redefinition of conditions, but finding the cite
323 ;;; and documenting it here would be good. (Or, if this is not in fact
324 ;;; ANSI-compliant, fixing it would also be good.:-)
325 (defun compute-effective-slots (class)
326 (collect ((res (copy-list (condition-classoid-slots class))))
327 (dolist (sclass (condition-classoid-cpl class))
328 (dolist (sslot (condition-classoid-slots sclass))
329 (let ((found (find (condition-slot-name sslot) (res))))
331 (setf (condition-slot-initargs found)
332 (union (condition-slot-initargs found)
333 (condition-slot-initargs sslot)))
334 (unless (condition-slot-initform-p found)
335 (setf (condition-slot-initform-p found)
336 (condition-slot-initform-p sslot))
337 (setf (condition-slot-initform found)
338 (condition-slot-initform sslot)))
339 (unless (condition-slot-allocation found)
340 (setf (condition-slot-allocation found)
341 (condition-slot-allocation sslot))))
343 (res (copy-structure sslot)))))))
346 (defun %define-condition (name slots documentation report default-initargs)
347 (let ((class (find-classoid name)))
348 (setf (condition-classoid-slots class) slots)
349 (setf (condition-classoid-report class) report)
350 (setf (condition-classoid-default-initargs class) default-initargs)
351 (setf (fdocumentation name 'type) documentation)
355 ;; Set up reader and writer functions.
356 (let ((name (condition-slot-name slot)))
357 (dolist (reader (condition-slot-readers slot))
358 (setf (fdefinition reader)
360 (condition-reader-function condition name))))
361 (dolist (writer (condition-slot-writers slot))
362 (setf (fdefinition writer)
363 (lambda (new-value condition)
364 (condition-writer-function condition new-value name))))))
366 ;; Compute effective slots and set up the class and hairy slots
367 ;; (subsets of the effective slots.)
368 (let ((eslots (compute-effective-slots class))
371 (mapcar #'condition-classoid-default-initargs
372 (condition-classoid-cpl class)))))
373 (dolist (slot eslots)
374 (ecase (condition-slot-allocation slot)
376 (unless (condition-slot-cell slot)
377 (setf (condition-slot-cell slot)
378 (list (if (condition-slot-initform-p slot)
379 (let ((initform (condition-slot-initform slot)))
380 (if (functionp initform)
383 *empty-condition-slot*))))
384 (push slot (condition-classoid-class-slots class)))
386 (setf (condition-slot-allocation slot) :instance)
387 (when (or (functionp (condition-slot-initform slot))
388 (dolist (initarg (condition-slot-initargs slot) nil)
389 (when (functionp (getf e-def-initargs initarg))
391 (push slot (condition-classoid-hairy-slots class))))))))
394 (defmacro define-condition (name (&rest parent-types) (&rest slot-specs)
397 "DEFINE-CONDITION Name (Parent-Type*) (Slot-Spec*) Option*
398 Define NAME as a condition type. This new type inherits slots and its
399 report function from the specified PARENT-TYPEs. A slot spec is a list of:
400 (slot-name :reader <rname> :initarg <iname> {Option Value}*
402 The DEFINE-CLASS slot options :ALLOCATION, :INITFORM, [slot] :DOCUMENTATION
403 and :TYPE and the overall options :DEFAULT-INITARGS and
404 [type] :DOCUMENTATION are also allowed.
406 The :REPORT option is peculiar to DEFINE-CONDITION. Its argument is either
407 a string or a two-argument lambda or function name. If a function, the
408 function is called with the condition and stream to report the condition.
409 If a string, the string is printed.
411 Condition types are classes, but (as allowed by ANSI and not as described in
412 CLtL2) are neither STANDARD-OBJECTs nor STRUCTURE-OBJECTs. WITH-SLOTS and
413 SLOT-VALUE may not be used on condition objects."
414 (let* ((parent-types (or parent-types '(condition)))
415 (layout (find-condition-layout name parent-types))
418 (default-initargs ()))
420 (all-readers nil append)
421 (all-writers nil append))
422 (dolist (spec slot-specs)
423 (when (keywordp spec)
424 (warn "Keyword slot name indicates probable syntax error:~% ~S"
426 (let* ((spec (if (consp spec) spec (list spec)))
427 (slot-name (first spec))
428 (allocation :instance)
434 (do ((options (rest spec) (cddr options)))
436 (unless (and (consp options) (consp (cdr options)))
437 (error "malformed condition slot spec:~% ~S." spec))
438 (let ((arg (second options)))
439 (case (first options)
440 (:reader (readers arg))
441 (:writer (writers arg))
444 (writers `(setf ,arg)))
447 (error "more than one :INITFORM in ~S" spec))
450 (:initarg (initargs arg))
452 (setq allocation arg))
455 (error "unknown slot option:~% ~S" (first options))))))
457 (all-readers (readers))
458 (all-writers (writers))
459 (slots `(make-condition-slot
461 :initargs ',(initargs)
464 :initform-p ',initform-p
466 ,(if (constantp initform)
468 `#'(lambda () ,initform)))))))
470 (dolist (option options)
471 (unless (consp option)
472 (error "bad option:~% ~S" option))
474 (:documentation (setq documentation (second option)))
476 (let ((arg (second option)))
479 `#'(lambda (condition stream)
480 (declare (ignore condition))
481 (write-string ,arg stream))
482 `#'(lambda (condition stream)
483 (funcall #',arg condition stream))))))
485 (do ((initargs (rest option) (cddr initargs)))
487 (let ((val (second initargs)))
488 (setq default-initargs
489 (list* `',(first initargs)
493 default-initargs)))))
495 (error "unknown option: ~S" (first option)))))
498 (eval-when (:compile-toplevel :load-toplevel :execute)
499 (%compiler-define-condition ',name ',parent-types ',layout))
501 (declaim (ftype (function (t) t) ,@(all-readers)))
502 (declaim (ftype (function (t t) t) ,@(all-writers)))
504 (%define-condition ',name
508 (list ,@default-initargs))))))
510 ;;;; DESCRIBE on CONDITIONs
512 ;;; a function to be used as the guts of DESCRIBE-OBJECT (CONDITION T)
513 ;;; eventually (once we get CLOS up and running so that we can define
515 (defun describe-condition (condition stream)
517 "~@<~S ~_is a ~S. ~_Its slot values are ~_~S.~:>"
521 (condition-actual-initargs condition)
522 (condition-assigned-slots condition))))
524 ;;;; various CONDITIONs specified by ANSI
526 (define-condition serious-condition (condition) ())
528 (define-condition error (serious-condition) ())
530 (define-condition warning (condition) ())
531 (define-condition style-warning (warning) ())
533 (defun simple-condition-printer (condition stream)
536 (simple-condition-format-control condition)
537 (simple-condition-format-arguments condition)))
539 (define-condition simple-condition ()
540 ((format-control :reader simple-condition-format-control
541 :initarg :format-control)
542 (format-arguments :reader simple-condition-format-arguments
543 :initarg :format-arguments
545 (:report simple-condition-printer))
547 (define-condition simple-warning (simple-condition warning) ())
549 (define-condition simple-error (simple-condition error) ())
551 (define-condition storage-condition (serious-condition) ())
553 (define-condition type-error (error)
554 ((datum :reader type-error-datum :initarg :datum)
555 (expected-type :reader type-error-expected-type :initarg :expected-type))
557 (lambda (condition stream)
559 "~@<The value ~2I~:_~S ~I~_is not of type ~2I~_~S.~:>"
560 (type-error-datum condition)
561 (type-error-expected-type condition)))))
563 (define-condition simple-type-error (simple-condition type-error) ())
565 (define-condition program-error (error) ())
566 (define-condition parse-error (error) ())
567 (define-condition control-error (error) ())
568 (define-condition stream-error (error)
569 ((stream :reader stream-error-stream :initarg :stream)))
571 (define-condition end-of-file (stream-error) ()
573 (lambda (condition stream)
576 (stream-error-stream condition)))))
578 (define-condition file-error (error)
579 ((pathname :reader file-error-pathname :initarg :pathname))
581 (lambda (condition stream)
582 (format stream "error on file ~S" (file-error-pathname condition)))))
584 (define-condition package-error (error)
585 ((package :reader package-error-package :initarg :package)))
587 (define-condition cell-error (error)
588 ((name :reader cell-error-name :initarg :name)))
590 (define-condition unbound-variable (cell-error) ()
592 (lambda (condition stream)
594 "The variable ~S is unbound."
595 (cell-error-name condition)))))
597 (define-condition undefined-function (cell-error) ()
599 (lambda (condition stream)
601 "The function ~S is undefined."
602 (cell-error-name condition)))))
604 (define-condition special-form-function (undefined-function) ()
606 (lambda (condition stream)
608 "Cannot FUNCALL the SYMBOL-FUNCTION of special operator ~S."
609 (cell-error-name condition)))))
611 (define-condition arithmetic-error (error)
612 ((operation :reader arithmetic-error-operation
615 (operands :reader arithmetic-error-operands
617 (:report (lambda (condition stream)
619 "arithmetic error ~S signalled"
621 (when (arithmetic-error-operation condition)
623 "~%Operation was ~S, operands ~S."
624 (arithmetic-error-operation condition)
625 (arithmetic-error-operands condition))))))
627 (define-condition division-by-zero (arithmetic-error) ())
628 (define-condition floating-point-overflow (arithmetic-error) ())
629 (define-condition floating-point-underflow (arithmetic-error) ())
630 (define-condition floating-point-inexact (arithmetic-error) ())
631 (define-condition floating-point-invalid-operation (arithmetic-error) ())
633 (define-condition print-not-readable (error)
634 ((object :reader print-not-readable-object :initarg :object))
636 (lambda (condition stream)
637 (let ((obj (print-not-readable-object condition))
639 (format stream "~S cannot be printed readably." obj)))))
641 (define-condition reader-error (parse-error stream-error)
643 :reader reader-error-format-control
644 :initarg :format-control)
646 :reader reader-error-format-arguments
647 :initarg :format-arguments
650 (lambda (condition stream)
651 (let ((error-stream (stream-error-stream condition)))
652 (format stream "READER-ERROR ~@[at ~W ~]on ~S:~%~?"
653 (file-position error-stream) error-stream
654 (reader-error-format-control condition)
655 (reader-error-format-arguments condition))))))
657 ;;;; various other (not specified by ANSI) CONDITIONs
659 ;;;; These might logically belong in other files; they're here, after
660 ;;;; setup of CONDITION machinery, only because that makes it easier to
661 ;;;; get cold init to work.
663 ;;; KLUDGE: a condition for floating point errors when we can't or
664 ;;; won't figure out what type they are. (In FreeBSD and OpenBSD we
665 ;;; don't know how, at least as of sbcl-0.6.7; in Linux we probably
666 ;;; know how but the old code was broken by the conversion to POSIX
667 ;;; signal handling and hasn't been fixed as of sbcl-0.6.7.)
669 ;;; FIXME: Perhaps this should also be a base class for all
670 ;;; floating point exceptions?
671 (define-condition floating-point-exception (arithmetic-error)
672 ((flags :initarg :traps
674 :reader floating-point-exception-traps))
675 (:report (lambda (condition stream)
677 "An arithmetic error ~S was signalled.~%"
679 (let ((traps (floating-point-exception-traps condition)))
682 "Trapping conditions are: ~%~{ ~S~^~}~%"
685 "No traps are enabled? How can this be?"
688 (define-condition index-too-large-error (type-error)
691 (lambda (condition stream)
693 "The index ~S is too large."
694 (type-error-datum condition)))))
696 (define-condition bounding-indices-bad-error (type-error)
697 ((object :reader bounding-indices-bad-object :initarg :object))
699 (lambda (condition stream)
700 (let* ((datum (type-error-datum condition))
703 (object (bounding-indices-bad-object condition)))
707 "The bounding indices ~S and ~S are bad for a sequence of length ~S."
708 start end (length object)))
710 ;; from WITH-ARRAY-DATA
712 "The START and END parameters ~S and ~S are bad for an array of total size ~S."
713 start end (array-total-size object))))))))
715 (define-condition nil-array-accessed-error (type-error)
717 (:report (lambda (condition stream)
719 "An attempt to access an array of element-type ~
720 NIL was made. Congratulations!"))))
722 (define-condition io-timeout (stream-error)
723 ((direction :reader io-timeout-direction :initarg :direction))
725 (lambda (condition stream)
726 (declare (type stream stream))
728 "I/O timeout ~(~A~)ing ~S"
729 (io-timeout-direction condition)
730 (stream-error-stream condition)))))
732 (define-condition namestring-parse-error (parse-error)
733 ((complaint :reader namestring-parse-error-complaint :initarg :complaint)
734 (args :reader namestring-parse-error-args :initarg :args :initform nil)
735 (namestring :reader namestring-parse-error-namestring :initarg :namestring)
736 (offset :reader namestring-parse-error-offset :initarg :offset))
738 (lambda (condition stream)
740 "parse error in namestring: ~?~% ~A~% ~V@T^"
741 (namestring-parse-error-complaint condition)
742 (namestring-parse-error-args condition)
743 (namestring-parse-error-namestring condition)
744 (namestring-parse-error-offset condition)))))
746 (define-condition simple-package-error (simple-condition package-error) ())
748 (define-condition reader-package-error (reader-error) ())
750 (define-condition reader-eof-error (end-of-file)
751 ((context :reader reader-eof-error-context :initarg :context))
753 (lambda (condition stream)
755 "unexpected end of file on ~S ~A"
756 (stream-error-stream condition)
757 (reader-eof-error-context condition)))))
759 (define-condition reader-impossible-number-error (reader-error)
760 ((error :reader reader-impossible-number-error-error :initarg :error))
762 (lambda (condition stream)
763 (let ((error-stream (stream-error-stream condition)))
764 (format stream "READER-ERROR ~@[at ~W ~]on ~S:~%~?~%Original error: ~A"
765 (file-position error-stream) error-stream
766 (reader-error-format-control condition)
767 (reader-error-format-arguments condition)
768 (reader-impossible-number-error-error condition))))))
770 ;;; should this inherit from error? good question
771 (define-condition timeout (error) ())
775 ;;;; special SBCL extension conditions
777 ;;; an error apparently caused by a bug in SBCL itself
779 ;;; Note that we don't make any serious effort to use this condition
780 ;;; for *all* errors in SBCL itself. E.g. type errors and array
781 ;;; indexing errors can occur in functions called from SBCL code, and
782 ;;; will just end up as ordinary TYPE-ERROR or invalid index error,
783 ;;; because the signalling code has no good way to know that the
784 ;;; underlying problem is a bug in SBCL. But in the fairly common case
785 ;;; that the signalling code does know that it's found a bug in SBCL,
786 ;;; this condition is appropriate, reusing boilerplate and helping
787 ;;; users to recognize it as an SBCL bug.
788 (define-condition bug (simple-error)
791 (lambda (condition stream)
794 (simple-condition-format-control condition)
795 (simple-condition-format-arguments condition)
796 "~@<This is probably a bug in SBCL itself. (Alternatively, ~
797 SBCL might have been corrupted by bad user code, e.g. by an ~
798 undefined Lisp operation like ~S, or by stray pointers from ~
799 alien code or from unsafe Lisp code; or there might be a bug ~
800 in the OS or hardware that SBCL is running on.) If it seems to ~
801 be a bug in SBCL itself, the maintainers would like to know ~
802 about it. Bug reports are welcome on the SBCL ~
803 mailing lists, which you can find at ~
804 <http://sbcl.sourceforge.net/>.~:@>"
805 '((fmakunbound 'compile))))))
806 (defun bug (format-control &rest format-arguments)
808 :format-control format-control
809 :format-arguments format-arguments))
811 ;;; a condition for use in stubs for operations which aren't supported
812 ;;; on some platforms
814 ;;; E.g. in sbcl-0.7.0.5, it might be appropriate to do something like
815 ;;; #-(or freebsd linux)
816 ;;; (defun load-foreign (&rest rest)
817 ;;; (error 'unsupported-operator :name 'load-foreign))
818 ;;; #+(or freebsd linux)
819 ;;; (defun load-foreign ... actual definition ...)
820 ;;; By signalling a standard condition in this case, we make it
821 ;;; possible for test code to distinguish between (1) intentionally
822 ;;; unimplemented and (2) unintentionally just screwed up somehow.
823 ;;; (Before this condition was defined, test code tried to deal with
824 ;;; this by checking for FBOUNDP, but that didn't work reliably. In
825 ;;; sbcl-0.7.0, a a package screwup left the definition of
826 ;;; LOAD-FOREIGN in the wrong package, so it was unFBOUNDP even on
827 ;;; architectures where it was supposed to be supported, and the
828 ;;; regression tests cheerfully passed because they assumed that
829 ;;; unFBOUNDPness meant they were running on an system which didn't
830 ;;; support the extension.)
831 (define-condition unsupported-operator (cell-error) ()
833 (lambda (condition stream)
835 "unsupported on this platform (OS, CPU, whatever): ~S"
836 (cell-error-name condition)))))
838 ;;;; restart definitions
840 (define-condition abort-failure (control-error) ()
842 "An ABORT restart was found that failed to transfer control dynamically."))
844 (defun abort (&optional condition)
846 "Transfer control to a restart named ABORT, signalling a CONTROL-ERROR if
848 (invoke-restart (find-restart 'abort condition))
849 ;; ABORT signals an error in case there was a restart named ABORT
850 ;; that did not transfer control dynamically. This could happen with
852 (error 'abort-failure))
854 (defun muffle-warning (&optional condition)
856 "Transfer control to a restart named MUFFLE-WARNING, signalling a
857 CONTROL-ERROR if none exists."
858 (invoke-restart (find-restart 'muffle-warning condition)))
860 (macrolet ((define-nil-returning-restart (name args doc)
861 #!-sb-doc (declare (ignore doc))
862 `(defun ,name (,@args &optional condition)
864 ;; FIXME: Perhaps this shared logic should be pulled out into
865 ;; FLET MAYBE-INVOKE-RESTART? See whether it shrinks code..
866 (let ((restart (find-restart ',name condition)))
868 (invoke-restart restart ,@args))))))
869 (define-nil-returning-restart continue ()
870 "Transfer control to a restart named CONTINUE, or return NIL if none exists.")
871 (define-nil-returning-restart store-value (value)
872 "Transfer control and VALUE to a restart named STORE-VALUE, or return NIL if
874 (define-nil-returning-restart use-value (value)
875 "Transfer control and VALUE to a restart named USE-VALUE, or return NIL if
878 (/show0 "condition.lisp end of file")