]> asedeno.scripts.mit.edu Git - cl-protobufs.git/blob - conditions.lisp
generalize CCL fasl ignores
[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 ;;; Protocol buffers conditions
14
15 (define-condition undefined-type (simple-error)
16   ((type-name :type string
17               :reader error-type-name
18               :initarg :type-name))
19   (:documentation "Indicates that a schema references a type which has not been defined.")
20   (:default-initargs :format-control "Undefined type:")
21   (:report (lambda (condition stream)
22              (format stream "~? ~S"
23                      (simple-condition-format-control condition)
24                      (simple-condition-format-arguments condition)
25                      (error-type-name condition)))))
26
27 (define-condition undefined-field-type (undefined-type)
28   ((field :type protobuf-field
29           :reader error-field
30           :initarg :field))
31   (:documentation "Indicates that a schema contains a message with a field whose type is not a
32                    primitive type and is not a known message (or extend) or enum.")
33   (:report (lambda (condition stream)
34              (format stream "~? Field ~A in message ~A has unknown type ~A"
35                      (simple-condition-format-control condition)
36                      (simple-condition-format-arguments condition)
37                      (error-field condition)
38                      (proto-parent (error-field condition))
39                      (error-type-name condition)))))
40
41 ;; The serializers use this a lot, so wrap it up
42 (defun undefined-field-type (format-control object type field)
43   (error 'undefined-field-type
44     :format-control format-control
45     :format-arguments (list object)
46     :type-name (prin1-to-string type)
47     :field field))
48
49 (define-condition undefined-method-type (undefined-type)
50   ((method :type protobuf-method
51            :reader error-method
52            :initarg :method)
53    (where :type string
54           :reader error-where
55           :initarg :where
56           :documentation "Description of which type referenced by the method is undefined."))
57   (:documentation "Superclass for `undefined-type' errors related to a `protobuf-method'.  Indicates
58                    that a schema contains a service with a method whose input, output, or stream
59                    type is not a known message (or extend).")
60   (:report (lambda (condition stream)
61              (format stream "~? ~A type for RPC ~A in service ~A has unknown type ~A"
62                      (simple-condition-format-control condition)
63                      (simple-condition-format-arguments condition)
64                      (error-where condition)
65                      (error-method condition)
66                      (proto-parent (error-method condition))
67                      (error-type-name condition)))))
68
69 (define-condition undefined-input-type (undefined-method-type)
70   ()
71   (:default-initargs :where "Input"))
72
73 (define-condition undefined-output-type (undefined-method-type)
74   ()
75   (:default-initargs :where "Output"))
76
77 (define-condition undefined-stream-type (undefined-method-type)
78   ()
79   (:default-initargs :where "Stream"))