-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathexc.py
More file actions
174 lines (118 loc) · 5.03 KB
/
exc.py
File metadata and controls
174 lines (118 loc) · 5.03 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
167
168
169
170
171
172
173
174
import json
import logging
logger = logging.getLogger(__name__)
### PEP-249 Mandated ###
# https://peps.python.org/pep-0249/#exceptions
class Error(Exception):
"""Base class for DB-API2.0 exceptions.
`message`: An optional user-friendly error message. It should be short, actionable and stable
`context`: Optional extra context about the error. MUST be JSON serializable
"""
def __init__(
self,
message=None,
context=None,
host_url=None,
*args,
session_id_hex=None,
**kwargs,
):
super().__init__(message, *args, **kwargs)
self.message = message
self.context = context or {}
error_name = self.__class__.__name__
if host_url:
from databricks.sql.telemetry.telemetry_client import TelemetryClientFactory
telemetry_client = TelemetryClientFactory.get_telemetry_client(
host_url=host_url
)
telemetry_client.export_failure_log(
error_name, self.message, session_id=session_id_hex
)
def __str__(self):
return self.message
def message_with_context(self):
return self.message + ": " + json.dumps(self.context, default=str)
class Warning(Exception):
pass
class InterfaceError(Error):
pass
class DatabaseError(Error):
pass
class InternalError(DatabaseError):
pass
class OperationalError(DatabaseError):
pass
class ProgrammingError(DatabaseError):
pass
class IntegrityError(DatabaseError):
pass
class DataError(DatabaseError):
pass
class NotSupportedError(DatabaseError):
pass
class TransactionError(DatabaseError):
"""
Exception raised for transaction-specific errors.
This exception is used when transaction control operations fail, such as:
- Setting autocommit mode (AUTOCOMMIT_SET_DURING_ACTIVE_TRANSACTION)
- Committing a transaction (MULTI_STATEMENT_TRANSACTION_NO_ACTIVE_TRANSACTION)
- Rolling back a transaction
- Setting transaction isolation level
The exception includes context about which transaction operation failed
and preserves the underlying cause via exception chaining.
"""
pass
### Custom error classes ###
class InvalidServerResponseError(OperationalError):
"""Thrown if the server does not set the initial namespace correctly"""
pass
class ServerOperationError(DatabaseError):
"""Thrown if the operation moved to an error state, if for example there was a syntax
error.
Its context will have the following keys:
"diagnostic-info": The full Spark stack trace (if available)
"operation-id": The Thrift ID of the operation
"""
pass
class RequestError(OperationalError):
"""Thrown if there was a error during request to the server.
Its context will have the following keys:
"method": The RPC method name that failed
"session-id": The Thrift session guid
"query-id": The Thrift query guid (if available)
"http-code": HTTP response code to RPC request (if available)
"error-message": Error message from the HTTP headers (if available)
"original-exception": The Python level original exception
"no-retry-reason": Why the request wasn't retried (if available)
"bounded-retry-delay": The maximum amount of time an error will be retried before giving up
"attempt": current retry number / maximum number of retries
"elapsed-seconds": time that has elapsed since first attempting the RPC request
"""
pass
class MaxRetryDurationError(RequestError):
"""Thrown if the next HTTP request retry would exceed the configured
stop_after_attempts_duration
"""
class NonRecoverableNetworkError(RequestError):
"""Thrown if an HTTP code 501 is received"""
class UnsafeToRetryError(RequestError):
"""Thrown if ExecuteStatement request receives a code other than 200, 429, or 503"""
class SessionAlreadyClosedError(RequestError):
"""Thrown if CloseSession receives a code 404. ThriftBackend should gracefully proceed as this is expected."""
class CursorAlreadyClosedError(RequestError):
"""Thrown if CancelOperation receives a code 404. ThriftBackend should gracefully proceed as this is expected."""
class TelemetryRateLimitError(Exception):
"""Raised when telemetry endpoint returns 429 or 503, indicating rate limiting or service unavailable.
This exception is used exclusively by the circuit breaker to track telemetry rate limiting events."""
class TelemetryNonRateLimitError(Exception):
"""Wrapper for telemetry errors that should NOT trigger circuit breaker.
This exception wraps non-rate-limiting errors (network errors, timeouts, server errors, etc.)
and is excluded from circuit breaker failure counting. Only TelemetryRateLimitError should
open the circuit breaker.
Attributes:
original_exception: The actual exception that occurred
"""
def __init__(self, original_exception: Exception):
self.original_exception = original_exception
super().__init__(f"Non-rate-limit telemetry error: {original_exception}")