163c0e37bd7697f67adccb7ee7b625ac68c0a431
[sbcl.git] / src / code / error.lisp
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
4
5 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; more information.
7 ;;;;
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.
13
14 (in-package "SB!KERNEL")
15
16 (define-condition simple-style-warning (simple-condition style-warning) ())
17
18 ;;; not sure this is the right place, but where else?
19 (defun style-warn (format-control &rest format-arguments)
20   (/show0 "entering STYLE-WARN")
21   (/show format-control format-arguments)
22   (warn 'simple-style-warning
23         :format-control format-control
24         :format-arguments format-arguments))
25
26 ;;; a utility for SIGNAL, ERROR, CERROR, WARN, COMPILER-NOTIFY and
27 ;;; INVOKE-DEBUGGER: Parse the hairy argument conventions into a
28 ;;; single argument that's directly usable by all the other routines.
29 (defun coerce-to-condition (datum arguments default-type fun-name)
30   (cond ((typep datum 'condition)
31          (if arguments
32              (cerror "Ignore the additional arguments."
33                      'simple-type-error
34                      :datum arguments
35                      :expected-type 'null
36                      :format-control "You may not supply additional arguments ~
37                                      when giving ~S to ~S."
38                      :format-arguments (list datum fun-name)))
39          datum)
40         ((symbolp datum) ; roughly, (SUBTYPEP DATUM 'CONDITION)
41          (apply #'make-condition datum arguments))
42         ((or (stringp datum) (functionp datum))
43          (make-condition default-type
44                          :format-control datum
45                          :format-arguments arguments))
46         (t
47          (error 'simple-type-error
48                 :datum datum
49                 :expected-type '(or symbol string)
50                 :format-control "bad argument to ~S: ~S"
51                 :format-arguments (list fun-name datum)))))
52
53 (define-condition layout-invalid (type-error)
54   ()
55   (:report
56    (lambda (condition stream)
57      (format stream
58              "~@<invalid structure layout: ~
59               ~2I~_A test for class ~4I~_~S ~
60               ~2I~_was passed the obsolete instance ~4I~_~S~:>"
61              (classoid-proper-name (type-error-expected-type condition))
62              (type-error-datum condition)))))
63
64 (define-condition case-failure (type-error)
65   ((name :reader case-failure-name :initarg :name)
66    (possibilities :reader case-failure-possibilities :initarg :possibilities))
67   (:report
68     (lambda (condition stream)
69       (format stream "~@<~S fell through ~S expression. ~
70                       ~:_Wanted one of ~:S.~:>"
71               (type-error-datum condition)
72               (case-failure-name condition)
73               (case-failure-possibilities condition)))))
74
75 (define-condition simple-control-error (simple-condition control-error) ())
76 (define-condition simple-file-error    (simple-condition file-error)    ())
77 (define-condition simple-program-error (simple-condition program-error) ())
78 (define-condition simple-stream-error  (simple-condition stream-error)  ())
79 (define-condition simple-parse-error   (simple-condition parse-error)   ())
80
81 (define-condition control-stack-exhausted (storage-condition)
82   ()
83   (:report
84     (lambda (condition stream)
85       (declare (ignore condition))
86       (format stream
87              "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."))))
88