-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy patherrors.lisp
147 lines (119 loc) · 5.28 KB
/
errors.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
(in-package :cloture)
(in-readtable clojure-shortcut)
(defcondition clojure-condition () ())
(defgeneric #_.getMessage (condition)
(:method ((c condition))
(princ-to-string c)))
(defcondition clojure-error (error clojure-condition)
((message :initarg :message)
(cause :initarg :cause :reader #_.getCause))
(:documentation "Sub-root of all Clojure conditions.")
(:default-initargs :cause #_nil)
(:report (lambda (c s)
(with-slots (message) c
(format s "~a" message)))))
(defmacro define-simple-error-constructor (name)
(let* ((ctor-name (string+ name "."))
(ctor (find-external-symbol ctor-name (symbol-package name) :error t)))
`(defsubst ,ctor (msg)
(make-condition ',name :message msg))))
(defmacro defcondition* (name supers &body body)
`(progn
(defcondition ,name ,supers
,@(if body body (list nil)))
(define-symbol-macro ,name (find-class ',name))))
(defcondition* #_Throwable (clojure-error))
(define-simple-error-constructor #_Throwable)
(defcondition* #_Exception (#_Throwable) ())
(define-simple-error-constructor #_Exception)
(defcondition* #_RuntimeException (#_Exception) ())
(define-simple-error-constructor #_RuntimeException)
(defcondition* #_IllegalArgumentException (#_RuntimeException) ())
(define-simple-error-constructor #_IllegalArgumentException)
(defcondition* #_IllegalStateException (#_RuntimeException) ())
(define-simple-error-constructor #_IllegalStateException)
(defcondition* #_ArityException (#_IllegalArgumentException)
((actual :initarg :actual)
(name :initarg :name))
(:report (lambda (c s)
(with-slots (name actual) c
(format s "~a got ~a arg~:p, which is the wrong arity."
(or name "Anonymous function") actual)))))
(defun #_ArityException. (actual name)
(make-condition '#_ArityException
:actual actual
:name name))
(defcondition* #_Error (#_Exception) ())
(define-simple-error-constructor #_Error)
(defcondition* #_AssertionError (#_Exception) ())
(define-simple-error-constructor #_AssertionError)
(defcondition* #_IllegalAccessError (#_Error) ()) ;Skipping some parents.
(define-simple-error-constructor #_IllegalAccessError)
(defcondition already-persistent (#_IllegalAccessError)
((transient :initarg :transient))
(:report (lambda (c s)
(with-slots (transient) c
(format s "Transient ~a has already been persisted."
transient)))))
(defcondition not-yet-implemented (#_Throwable)
((what :initarg :what))
(:report (lambda (c s)
(with-slots (what) c
(format s "Not yet implemented: ~a" what)))))
(defcondition simple-clojure-error (clojure-condition simple-error) ())
(defcondition clojure-program-error (program-error clojure-error) ())
(defcondition simple-clojure-program-error (clojure-program-error simple-condition) ())
(defcondition clojure-reader-error (clojure-error reader-error) ())
(defcondition simple-clojure-reader-error (simple-clojure-error reader-error) ())
(defcondition clojure-package-error (clojure-error package-error) ())
(defcondition clojure-syntax-error (clojure-error) ())
(defcondition simple-clojure-syntax-error (simple-error clojure-syntax-error) ())
(defcondition wrong-number-arguments (clojure-program-error)
((arguments :initarg :arguments)))
(defcondition too-many-arguments (wrong-number-arguments)
((max :initarg :max :type (integer 0 *)))
(:report (lambda (c s)
(with-slots (arguments max) c
(format s "Too many arguments (max ~a):~%~s" max arguments)))))
(defcondition too-few-arguments (wrong-number-arguments)
((min :initarg :max :type (integer 0 *)))
(:report (lambda (c s)
(with-slots (arguments max) c
(format s "Too many arguments (max ~a):~%~s" max arguments)))))
(defun clojure-error (control &rest args)
(make-condition 'simple-clojure-error
:format-control control
:format-arguments args))
(defun clojure-syntax-error (control &rest args)
(make-condition 'simple-clojure-syntax-error
:format-control control
:format-arguments args))
(defun clojure-program-error (control &rest args)
(make-condition 'simple-clojure-program-error
:format-control control
:format-arguments args))
(defun clojure-reader-error (control &rest args)
(make-condition 'simple-clojure-reader-error
:format-control control
:format-arguments args))
(defun too-many-arguments (max-arity args)
(error 'too-many-arguments
:max max-arity
:arguments args))
(defun too-few-arguments (max-arity args)
(error 'too-few-arguments
:max max-arity
:arguments args))
(defcondition does-not-extend (clojure-error)
((protocol :initarg :protocol)
(object :initarg :object))
(:report (lambda (c s)
(with-slots (protocol object) c
(format s "Class of ~a does not extend protocol ~a"
object protocol)))))
(defcondition no-such-method (clojure-error)
((multi :initarg :multi)
(value :initarg :value))
(:report (lambda (c s)
(with-slots (multi value) c
(format s "No method for ~a in multimethod ~a" value multi)))))