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 (format-control &rest format-arguments)
18 (/show0 "entering STYLE-WARN")
19 (/show format-control format-arguments)
21 (warn 'simple-style-warning
22 :format-control format-control
23 :format-arguments format-arguments)))
25 ;;; a utility for SIGNAL, ERROR, CERROR, WARN, COMPILER-NOTIFY and
26 ;;; INVOKE-DEBUGGER: Parse the hairy argument conventions into a
27 ;;; single argument that's directly usable by all the other routines.
28 (defun coerce-to-condition (datum arguments default-type fun-name)
29 (cond ((typep datum 'condition)
30 (when (and arguments (not (eq fun-name 'cerror)))
31 (cerror "Ignore the additional arguments."
35 :format-control "You may not supply additional arguments ~
36 when giving ~S to ~S."
37 :format-arguments (list datum fun-name)))
39 ((symbolp datum) ; roughly, (SUBTYPEP DATUM 'CONDITION)
40 (apply #'make-condition datum arguments))
41 ((or (stringp datum) (functionp datum))
42 (make-condition default-type
44 :format-arguments arguments))
46 (error 'simple-type-error
48 :expected-type '(or symbol string)
49 :format-control "bad argument to ~S: ~S"
50 :format-arguments (list fun-name datum)))))
52 (define-condition layout-invalid (type-error)
55 (lambda (condition stream)
57 "~@<invalid structure layout: ~
58 ~2I~_A test for class ~4I~_~S ~
59 ~2I~_was passed the obsolete instance ~4I~_~S~:>"
60 (classoid-proper-name (type-error-expected-type condition))
61 (type-error-datum condition)))))
63 (define-condition case-failure (type-error)
64 ((name :reader case-failure-name :initarg :name)
65 (possibilities :reader case-failure-possibilities :initarg :possibilities))
67 (lambda (condition stream)
68 (format stream "~@<~S fell through ~S expression. ~
69 ~:_Wanted one of ~:S.~:>"
70 (type-error-datum condition)
71 (case-failure-name condition)
72 (case-failure-possibilities condition)))))
74 (define-condition compiled-program-error (program-error)
75 ((message :initarg :message :reader program-error-message)
76 (source :initarg :source :reader program-error-source))
77 (:report (lambda (condition stream)
78 (format stream "Execution of a form compiled with errors.~%~
80 Compile-time-error:~% ~A"
81 (program-error-source condition)
82 (program-error-message condition)))))
84 (define-condition simple-control-error (simple-condition control-error) ())
85 (define-condition simple-file-error (simple-condition file-error) ())
86 (define-condition simple-program-error (simple-condition program-error) ())
87 (define-condition simple-stream-error (simple-condition stream-error) ())
88 (define-condition simple-parse-error (simple-condition parse-error) ())
90 (define-condition character-coding-error (error) ())
91 (define-condition character-encoding-error (character-coding-error)
92 ((code :initarg :code :reader character-encoding-error-code)))
93 (define-condition character-decoding-error (character-coding-error)
94 ((octets :initarg :octets :reader character-decoding-error-octets)))
95 (define-condition stream-encoding-error (stream-error character-encoding-error)
99 (let ((stream (stream-error-stream c))
100 (code (character-encoding-error-code c)))
101 (format s "~@<encoding error on stream ~S (~S ~S): ~2I~_~
102 the character with code ~D cannot be encoded.~@:>"
103 stream ':external-format (stream-external-format stream)
105 (define-condition stream-decoding-error (stream-error character-decoding-error)
109 (let ((stream (stream-error-stream c))
110 (octets (character-decoding-error-octets c)))
111 (format s "~@<decoding error on stream ~S (~S ~S): ~2I~_~
112 the octet sequence ~S cannot be decoded.~@:>"
113 stream ':external-format (stream-external-format stream)
116 (define-condition control-stack-exhausted (storage-condition)
119 (lambda (condition stream)
120 (declare (ignore condition))
122 "Control stack exhausted (no more space for function call frames). This is probably due to heavily nested or infinitely recursive function calls, or a tail call that SBCL cannot or has not optimized away."))))
124 (define-condition memory-fault-error (error)
127 (lambda (condition stream)
128 (declare (ignore condition))
129 (format stream "memory fault"))))