-
Notifications
You must be signed in to change notification settings - Fork 2
/
error.lisp
78 lines (68 loc) · 2.9 KB
/
error.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
(in-package :openapi-parser)
(defun path-to-string (path)
(format nil "~{~A~^.~}" path))
(defun print-error-header (condition stream)
(when-let (file (openapi-parser-condition-context-file condition))
(format stream "File: ~A~%" file))
(format stream "Path: ~A~%" (path-to-string (openapi-parser-condition-context-path condition)))
(when-let (line (compute-line-number-from-path (openapi-parser-condition-context-file condition)
(openapi-parser-condition-context-path condition)))
(format stream "Line: ~A~%" line))
(when (slot-boundp condition 'expected-type)
(format stream "Expected type: ~A~%" (openapi-parser-condition-context-expected-type condition))))
(define-condition openapi-parser-condition-context ()
((file
:initarg :file
:initform nil
:reader openapi-parser-condition-context-file)
(path
:initarg :path
:initform (get-path)
:reader openapi-parser-condition-context-path)
(expected-type
:initarg :expected-type
:reader openapi-parser-condition-context-expected-type)))
(define-condition openapi-parser-error (simple-error openapi-parser-condition-context)
())
(define-condition openapi-parser-warning (simple-warning openapi-parser-condition-context)
())
(define-condition out-of-spec-key (openapi-parser-warning)
((key :initarg :key))
(:report (lambda (c s)
(with-slots (key) c
(print-error-header c s)
(format s "Out of specification key '~A'" key)))))
(define-condition missing-field (openapi-parser-error)
((name :initarg :name
:reader missing-field-name))
(:report (lambda (c s)
(with-slots (path name) c
(print-error-header c s)
(format s "Missing field key '~A'" name)))))
(define-condition invalid-value (openapi-parser-error)
((key :initarg :key
:reader invalid-value-key)
(value :initarg :value
:reader invalid-value-value))
(:report (lambda (c s)
(with-slots (path key value expected-type) c
(print-error-header c s)
;; (format s "The value ~S for key ~S is invalid" value key)
(format s "The actual type ~S is not of expected type ~S"
(type-of value)
expected-type)))))
(define-condition invalid-all-values (invalid-value)
((errors :initarg :errors
:reader invalid-all-values-errors))
(:report (lambda (c s)
(with-slots (errors) c
(print-error-header c s)
(format s "The following errors~%")
(format s "~%~{~A~^~2%~}" errors)))))
(define-condition no-such-field-error (openapi-parser-error)
((ref :initarg :ref
:reader no-such-field-error-ref))
(:report (lambda (c s)
(with-slots (ref) c
(print-error-header c s)
(format s "No such field ~S~%" ref)))))