]> asedeno.scripts.mit.edu Git - cl-protobufs.git/blob - conditions.lisp
Don't kluge *asdf-verbose* on asdf3.
[cl-protobufs.git] / conditions.lisp
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;;;                                                                  ;;;
3 ;;; Free Software published under an MIT-like license. See LICENSE   ;;;
4 ;;;                                                                  ;;;
5 ;;; Copyright (c) 2012 Google, Inc.  All rights reserved.            ;;;
6 ;;;                                                                  ;;;
7 ;;; Original author: Ben Wagner                                      ;;;
8 ;;;                                                                  ;;;
9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10
11 (in-package "PROTO-IMPL")
12
13
14 ;;; Protocol buffers conditions
15
16 (define-condition undefined-type (simple-error)
17   ((type-name :type string
18               :reader error-type-name
19               :initarg :type-name))
20   (:documentation "Indicates that a schema references a type which has not been defined.")
21   (:default-initargs :format-control "Undefined type:")
22   (:report (lambda (condition stream)
23              (format stream "~? ~S"
24                      (simple-condition-format-control condition)
25                      (simple-condition-format-arguments condition)
26                      (error-type-name condition)))))
27
28 (define-condition undefined-field-type (undefined-type)
29   ((field :type protobuf-field
30           :reader error-field
31           :initarg :field))
32   (:documentation "Indicates that a schema contains a message with a field whose type is not a
33                    primitive type and is not a known message (or extend) or enum.")
34   (:report (lambda (condition stream)
35              (format stream "~? Field ~A in message ~A has unknown type ~A"
36                      (simple-condition-format-control condition)
37                      (simple-condition-format-arguments condition)
38                      (error-field condition)
39                      (proto-parent (error-field condition))
40                      (error-type-name condition)))))
41
42 ;; The serializers use this a lot, so wrap it up
43 (defun undefined-field-type (format-control object type field)
44   (error 'undefined-field-type
45     :format-control format-control
46     :format-arguments (list object)
47     :type-name (prin1-to-string type)
48     :field field))
49
50 (define-condition undefined-method-type (undefined-type)
51   ((method :type protobuf-method
52            :reader error-method
53            :initarg :method)
54    (where :type string
55           :reader error-where
56           :initarg :where
57           :documentation "Description of which type referenced by the method is undefined."))
58   (:documentation "Superclass for `undefined-type' errors related to a `protobuf-method'.  Indicates
59                    that a schema contains a service with a method whose input, output, or stream
60                    type is not a known message (or extend).")
61   (:report (lambda (condition stream)
62              (format stream "~? ~A type for RPC ~A in service ~A has unknown type ~A"
63                      (simple-condition-format-control condition)
64                      (simple-condition-format-arguments condition)
65                      (error-where condition)
66                      (error-method condition)
67                      (proto-parent (error-method condition))
68                      (error-type-name condition)))))
69
70 (define-condition undefined-input-type (undefined-method-type)
71   ()
72   (:default-initargs :where "Input"))
73
74 (define-condition undefined-output-type (undefined-method-type)
75   ()
76   (:default-initargs :where "Output"))
77
78 (define-condition undefined-stream-type (undefined-method-type)
79   ()
80   (:default-initargs :where "Stream"))
81
82
83 ;;; (De)serialization errors
84
85 (define-condition serialization-error (simple-error)
86   ()
87   (:documentation "Indicates that some sort of (de)serialization error has occurred.")
88   (:default-initargs :format-control "Serialization error")
89   (:report (lambda (condition stream)
90              (format stream "~?"
91                      (simple-condition-format-control condition)
92                      (simple-condition-format-arguments condition)))))
93
94 (defun serialization-error (format-control &rest format-args)
95   (error 'serialization-error
96     :format-control format-control
97     :format-arguments (copy-list format-args)))