-
Notifications
You must be signed in to change notification settings - Fork 599
Expand file tree
/
Copy pathexceptions.py
More file actions
166 lines (100 loc) · 5.2 KB
/
exceptions.py
File metadata and controls
166 lines (100 loc) · 5.2 KB
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
# Copyright (c) 2023 Boston Dynamics, Inc. All rights reserved.
#
# Downloading, reproducing, distributing or otherwise using the SDK Software
# is subject to the terms and conditions of the Boston Dynamics Software
# Development Kit License (20191101-BDSDK-SL).
class Error(Exception):
"""Base exception that all public api exceptions are derived from."""
class ResponseError(Error):
"""Exception triggered by a server response whose rpc succeeded."""
def __init__(self, response, error_message=None):
super(ResponseError, self).__init__()
self.response = response
if error_message is not None:
self.error_message = error_message
elif response is not None:
self.error_message = response.header.error.message
else:
self.error_message = ""
def __str__(self):
if self.response is not None:
full_classname = self.response.DESCRIPTOR.full_name
else:
full_classname = "Error"
return '{} ({}): {}'.format(full_classname, self.__class__.__name__, self.error_message)
class InvalidRequestError(ResponseError):
"""The provided request arguments are ill-formed or invalid, independent of the system state."""
class LeaseUseError(ResponseError):
"""Request was rejected due to using an invalid lease."""
def __init__(self, response, lease_use_result):
super().__init__(response)
self.lease_use_result = lease_use_result
class LicenseError(ResponseError):
"""Request was rejected due to using an invalid license."""
class ServerError(ResponseError):
"""Service encountered an unrecoverable error."""
class InternalServerError(ServerError):
"""Service experienced an unexpected error state."""
class UnsetStatusError(ServerError):
"""Response's status field (in either message or common header) was UNKNOWN value."""
class RpcError(Error):
"""An error occurred trying to reach a service on the robot."""
def __init__(self, original_error, error_message=None):
super(RpcError, self).__init__()
self.error = original_error
self.error_message = error_message or str(original_error)
def __str__(self):
return '{}: {}'.format(self.__class__.__name__, self.error_message)
class RetryableRpcError(RpcError):
"""An RpcError that denotes the same request may succeed if retried."""
class PersistentRpcError(RpcError):
"""An RpcError that will almost certainly continue to keep failing if retried"""
class ClientCancelledOperationError(PersistentRpcError):
"""The user cancelled the rpc request."""
class InvalidClientCertificateError(PersistentRpcError):
"""The provided client certificate is invalid."""
class NonexistentAuthorityError(PersistentRpcError):
"""The app token's authority field names a nonexistent service."""
class PermissionDeniedError(PersistentRpcError):
"""The rpc request was denied access."""
class ProxyConnectionError(RetryableRpcError):
"""The proxy on the robot could not be reached."""
class ResponseTooLargeError(RetryableRpcError):
"""The rpc response was larger than allowed max size."""
class ServiceUnavailableError(RetryableRpcError):
"""The proxy could not find the (possibly unregistered) service."""
class TooManyRequestsError(RetryableRpcError):
"""The remote procedure call did not go through the proxy due to rate limiting."""
class ServiceFailedDuringExecutionError(RetryableRpcError):
"""The service encountered an unexpected failure."""
class TimedOutError(RetryableRpcError):
"""The remote procedure call did not terminate within the allotted time."""
class UnableToConnectToRobotError(RetryableRpcError):
"""The robot may be offline or otherwise unreachable."""
class RetryableUnavailableError(UnableToConnectToRobotError):
"""Service unavailable or channel reset. Likely transient and can be resolved by retrying."""
class UnauthenticatedError(PersistentRpcError):
"""The user needs to authenticate or does not have permission to access requested service."""
class UnknownDnsNameError(PersistentRpcError):
"""The system is unable to translate the domain name."""
class NotFoundError(PersistentRpcError):
"""The backend system could not be found."""
class UnimplementedError(PersistentRpcError):
"""The API does not recognize the request and is unable to complete the request."""
class TransientFailureError(RetryableRpcError):
"""The channel is in state TRANSIENT_FAILURE, often caused by a connection failure."""
class TimeSyncRequired(Error):
"""Time synchronization is required but none seems to be established."""
class CustomParamError(ResponseError):
"""A custom parameter that was provided did not match the specification"""
def __init__(self, response, custom_param_error):
super().__init__(response)
self.custom_param_error = custom_param_error
def __str__(self):
if self.response is not None:
full_classname = self.response.DESCRIPTOR.full_name
else:
full_classname = "Error"
return '{} ({}): Parameter Errors\n{}'.format(
full_classname, self.__class__.__name__,
'\n'.join(self.custom_param_error.error_messages))