|
1 #!/usr/bin/env python |
|
2 # |
|
3 # Copyright 2007 Google Inc. |
|
4 # |
|
5 # Licensed under the Apache License, Version 2.0 (the "License"); |
|
6 # you may not use this file except in compliance with the License. |
|
7 # You may obtain a copy of the License at |
|
8 # |
|
9 # http://www.apache.org/licenses/LICENSE-2.0 |
|
10 # |
|
11 # Unless required by applicable law or agreed to in writing, software |
|
12 # distributed under the License is distributed on an "AS IS" BASIS, |
|
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 # See the License for the specific language governing permissions and |
|
15 # limitations under the License. |
|
16 # |
|
17 |
|
18 """Errors used in the YAML API, which is used by app developers.""" |
|
19 |
|
20 |
|
21 |
|
22 class Error(Exception): |
|
23 """Base datastore yaml error type.""" |
|
24 |
|
25 class ProtocolBufferParseError(Error): |
|
26 """Error in protocol buffer parsing""" |
|
27 |
|
28 |
|
29 class EmptyConfigurationFile(Error): |
|
30 """Tried to load empty configuration file.""" |
|
31 |
|
32 |
|
33 class MultipleConfigurationFile(Error): |
|
34 """Tried to load configuration file with multiple objects.""" |
|
35 |
|
36 |
|
37 class UnexpectedAttribute(Error): |
|
38 """Raised when an unexpected attribute is encounted.""" |
|
39 |
|
40 |
|
41 class DuplicateAttribute(Error): |
|
42 """Generated when an attribute is assigned to twice.""" |
|
43 |
|
44 |
|
45 class ListenerConfigurationError(Error): |
|
46 """Generated when there is a parsing problem due to configuration.""" |
|
47 |
|
48 |
|
49 class IllegalEvent(Error): |
|
50 """Raised when an unexpected event type is received by listener.""" |
|
51 |
|
52 |
|
53 class InternalError(Error): |
|
54 """Raised when an internal implementation error is detected.""" |
|
55 |
|
56 |
|
57 class EventListenerError(Error): |
|
58 """Top level exception raised by YAML listener. |
|
59 |
|
60 Any exception raised within the process of parsing a YAML file via an |
|
61 EventListener is caught and wrapped in an EventListenerError. The causing |
|
62 exception is maintained, but additional useful information is saved which |
|
63 can be used for reporting useful information to users. |
|
64 |
|
65 Attributes: |
|
66 cause: The original exception which caused the EventListenerError. |
|
67 """ |
|
68 |
|
69 def __init__(self, cause): |
|
70 """Initialize event-listener error.""" |
|
71 if hasattr(cause, 'args'): |
|
72 Error.__init__(self, *cause.args) |
|
73 else: |
|
74 Error.__init__(self, str(cause)) |
|
75 self.cause = cause |
|
76 |
|
77 |
|
78 class EventListenerYAMLError(EventListenerError): |
|
79 """Generated specifically for yaml.error.YAMLError.""" |
|
80 |
|
81 |
|
82 class EventError(EventListenerError): |
|
83 """Generated specifically when an error occurs in event handler. |
|
84 |
|
85 Attributes: |
|
86 cause: The original exception which caused the EventListenerError. |
|
87 event: Event being handled when exception occured. |
|
88 """ |
|
89 |
|
90 def __init__(self, cause, event): |
|
91 """Initialize event-listener error.""" |
|
92 EventListenerError.__init__(self, cause) |
|
93 self.event = event |
|
94 |
|
95 def __str__(self): |
|
96 return '%s\n%s' % (self.cause, self.event.start_mark) |