forked from databricks/databricks-sql-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexc.py
More file actions
128 lines (84 loc) · 3.5 KB
/
exc.py
File metadata and controls
128 lines (84 loc) · 3.5 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
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, session_id_hex=None, *args, **kwargs
):
super().__init__(message, *args, **kwargs)
self.message = message
self.context = context or {}
error_name = self.__class__.__name__
if session_id_hex:
from databricks.sql.telemetry.telemetry_client import TelemetryClientFactory
telemetry_client = TelemetryClientFactory.get_telemetry_client(
session_id_hex
)
telemetry_client.export_failure_log(error_name, self.message)
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
### 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."""