Skip to content

Commit cf33155

Browse files
Add error details
1 parent 220eaad commit cf33155

File tree

4 files changed

+407
-19
lines changed

4 files changed

+407
-19
lines changed

databricks/sdk/errors/base.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55

66
import requests
77

8+
from . import details as errdetails
89

9-
class ErrorDetail:
1010

11+
# Deprecated.
12+
class ErrorDetail:
13+
1114
def __init__(
1215
self,
1316
type: str = None,
@@ -31,9 +34,6 @@ def from_dict(cls, d: Dict[str, any]) -> "ErrorDetail":
3134
class DatabricksError(IOError):
3235
"""Generic error from Databricks REST API"""
3336

34-
# Known ErrorDetail types
35-
_error_info_type = "type.googleapis.com/google.rpc.ErrorInfo"
36-
3737
def __init__(
3838
self,
3939
message: str = None,
@@ -55,11 +55,11 @@ def __init__(
5555
:param status: [Deprecated]
5656
:param scimType: [Deprecated]
5757
:param error: [Deprecated]
58-
:param retry_after_secs:
58+
:param retry_after_secs: [Deprecated]
5959
:param details:
6060
:param kwargs:
6161
"""
62-
# SCIM-specific parameters are deprecated
62+
# SCIM-specific parameters are deprecated.
6363
if detail:
6464
warnings.warn(
6565
"The 'detail' parameter of DatabricksError is deprecated and will be removed in a future version."
@@ -73,12 +73,18 @@ def __init__(
7373
"The 'status' parameter of DatabricksError is deprecated and will be removed in a future version."
7474
)
7575

76-
# API 1.2-specific parameters are deprecated
76+
# API 1.2-specific parameters are deprecated.
7777
if error:
7878
warnings.warn(
7979
"The 'error' parameter of DatabricksError is deprecated and will be removed in a future version."
8080
)
8181

82+
# Retry-after is deprecated.
83+
if retry_after_secs:
84+
warnings.warn(
85+
"The 'retry_after_secs' parameter of DatabricksError is deprecated and will be removed in a future version."
86+
)
87+
8288
if detail:
8389
# Handle SCIM error message details
8490
# @see https://tools.ietf.org/html/rfc7644#section-3.7.3
@@ -89,20 +95,30 @@ def __init__(
8995
# add more context from SCIM responses
9096
message = f"{scimType} {message}".strip(" ")
9197
error_code = f"SCIM_{status}"
98+
9299
super().__init__(message if message else error)
93100
self.error_code = error_code
94101
self.retry_after_secs = retry_after_secs
95-
self.details = [ErrorDetail.from_dict(detail) for detail in details] if details else []
102+
103+
parsed_details = [errdetails.parse_json_details(d) for d in details] if details else []
104+
self._error_details = errdetails.parse_error_details(parsed_details)
105+
96106
self.kwargs = kwargs
97107

108+
# Deprecated.
109+
self.details = [ErrorDetail.from_dict(d) for d in details] if details else []
110+
98111
def get_error_info(self) -> List[ErrorDetail]:
99-
return self._get_details_by_type(DatabricksError._error_info_type)
112+
return self._get_details_by_type(errdetails._ERROR_INFO_TYPE)
100113

101114
def _get_details_by_type(self, error_type) -> List[ErrorDetail]:
102-
if self.details == None:
115+
if self.details is None:
103116
return []
104117
return [detail for detail in self.details if detail.type == error_type]
105118

119+
def get_error_details(self) -> errdetails.ErrorDetails:
120+
return self._error_details
121+
106122

107123
@dataclass
108124
class _ErrorOverride:

0 commit comments

Comments
 (0)