Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit963d5b0

Browse files
NiallEgansusodapop
authored andcommitted
Use simple error messages if available + better error message API
This PR has two main aims:1. Use the `displayMessage` if it has been set on the Thrift response2. Modify error messages so they have a user-friendly error message and full-context part, giving application builders more flexibility in how they construct any end-messages to the user* New unit tests - Did you add usage logs or metrics? Please mention them here. - Create dashboards or monitoring notebooks? Please link them here. - See http://go/obs/user for docs on our observability tools.
1 parentbcc6754 commit963d5b0

File tree

5 files changed

+3128
-122
lines changed

5 files changed

+3128
-122
lines changed

‎cmdexec/clients/python/src/databricks/sql/exc.py‎

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
1+
importjson
2+
importlogging
3+
4+
logger=logging.getLogger(__name__)
5+
6+
17
### PEP-249 Mandated ###
28
classError(Exception):
3-
pass
9+
"""Base class for DB-API2.0 exceptions.
10+
`message`: An optional user-friendly error message. It should be short, actionable and stable
11+
`context`: Optional extra context about the error. MUST be JSON serializable
12+
"""
13+
14+
def__init__(self,message=None,context=None,*args,**kwargs):
15+
super().__init__(message,*args,**kwargs)
16+
self.message=message
17+
self.context=contextor {}
18+
19+
def__str__(self):
20+
returnself.message
21+
22+
defmessage_with_context(self):
23+
returnself.message+": "+json.dumps(self.context,default=str)
424

525

626
classWarning(Exception):
@@ -41,5 +61,32 @@ class NotSupportedError(DatabaseError):
4161

4262
### Custom error classes ###
4363
classInvalidServerResponseError(OperationalError):
44-
""" Thrown if the server does not set the initial namespace correctly"""
64+
"""Thrown if the server does not set the initial namespace correctly"""
65+
pass
66+
67+
68+
classServerOperationError(DatabaseError):
69+
"""Thrown if the operation moved to an error state, if for example there was a syntax
70+
error.
71+
Its context will have the following keys:
72+
"diagnostic-info": The full Spark stack trace (if available)
73+
"operation-id": The Thrift ID of the operation
74+
"""
75+
pass
76+
77+
78+
classRequestError(OperationalError):
79+
"""Thrown if there was a error during request to the server.
80+
Its context will have the following keys:
81+
"method": The RPC method name that failed
82+
"session-id": The Thrift session guid
83+
"query-id": The Thrift query guid (if available)
84+
"http-code": HTTP response code to RPC request (if available)
85+
"error-message": Error message from the HTTP headers (if available)
86+
"original-exception": The Python level original exception
87+
"no-retry-reason": Why the request wasn't retried (if available)
88+
"bounded-retry-delay": The maximum amount of time an error will be retried before giving up
89+
"attempt": current retry number / maximum number of retries
90+
"elapsed-seconds": time that has elapsed since first attempting the RPC request
91+
"""
4592
pass

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp