This repository was archived by the owner on Jan 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy patherrors.py
205 lines (141 loc) · 5.23 KB
/
errors.py
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# Copyright (c) 2016 Uber Technologies, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from __future__ import absolute_import
#: The request timed out.
TIMEOUT = 0x01
#: The request was canceled.
CANCELED = 0x02
#: The server was busy.
BUSY = 0x03
# The server declined the request.
DECLINED = 0x04
# The server's handler raised an unexpected exception.
UNEXPECTED_ERROR = 0x05
#: The request was bad.
BAD_REQUEST = 0x06
#: There was a network error when sending the request.
NETWORK_ERROR = 0x07
#: The server handling the request is unhealthy.
UNHEALTHY = 0x08
#: There was a fatal protocol-level error.
FATAL = 0xFF
class TChannelError(Exception):
"""A TChannel-generated exception.
:ivar code:
The error code for this error. See the `Specification`_ for a
description of these codes.
:vartype code:
.. _`Specification`:
http://tchannel.readthedocs.org/en/latest/protocol/#code1_1
"""
__slots__ = (
'description',
'id',
'tracing',
)
code = None
def __init__(
self,
description=None,
id=None,
tracing=None,
):
super(TChannelError, self).__init__(description)
self.tracing = tracing
self.id = id
self.description = description
@classmethod
def from_code(cls, code, **kw):
"""Construct a ``TChannelError`` instance from an error code.
This will return the appropriate class type for the given code.
"""
return {
TIMEOUT: TimeoutError,
CANCELED: CanceledError,
BUSY: BusyError,
DECLINED: DeclinedError,
UNEXPECTED_ERROR: UnexpectedError,
BAD_REQUEST: BadRequestError,
NETWORK_ERROR: NetworkError,
UNHEALTHY: UnhealthyError,
FATAL: FatalProtocolError,
}[code](**kw)
class RetryableError(TChannelError):
"""An error where the original request is always safe to retry.
It is always safe to retry a request with this category of errors. The
original request was never handled.
"""
class MaybeRetryableError(TChannelError):
"""An error where the original request may be safe to retry.
The original request may have reached the intended service. Hence, the
request should only be retried if it is known to be `idempotent`_.
.. _`idempotent`:
https://en.wikipedia.org/wiki/Idempotence#Computer_science_meaning
"""
class NotRetryableError(TChannelError):
"""An error where the original request should not be re-sent.
Something was fundamentally wrong with the request and it should not be
retried.
"""
class TimeoutError(MaybeRetryableError):
code = TIMEOUT
class CanceledError(NotRetryableError):
code = CANCELED
class BusyError(RetryableError):
code = BUSY
class DeclinedError(RetryableError):
code = DECLINED
class UnexpectedError(MaybeRetryableError):
code = UNEXPECTED_ERROR
class BadRequestError(NotRetryableError):
code = BAD_REQUEST
class NetworkError(MaybeRetryableError):
code = NETWORK_ERROR
class UnhealthyError(NotRetryableError):
code = UNHEALTHY
class FatalProtocolError(NotRetryableError):
code = FATAL
class ReadError(FatalProtocolError):
"""Raised when there is an error while reading input."""
pass
class InvalidChecksumError(FatalProtocolError):
"""Represent invalid checksum type in the message"""
pass
class NoAvailablePeerError(RetryableError):
"""Represents a failure to find any peers for a request."""
pass
class AlreadyListeningError(FatalProtocolError):
"""Raised when attempting to listen multiple times."""
pass
class OneWayNotSupportedError(BadRequestError):
"""Raised when a one-way Thrift procedure is called."""
pass
class ValueExpectedError(BadRequestError):
"""Raised when a non-void Thrift response contains no value."""
pass
class SingletonNotPreparedError(TChannelError):
"""Raised when calling get_instance before calling prepare."""
pass
class ServiceNameIsRequiredError(Exception):
"""Raised when service name is empty or None."""
def __init__(self):
super(ServiceNameIsRequiredError, self).__init__(
"service name cannot be empty or None"
)