Skip to content

Commit

Permalink
Rename databricks.sdk.errors.mapping to `databricks.sdk.errors.plat…
Browse files Browse the repository at this point in the history
…form` (#522)

`databricks.sdk.errors.mapping.ResourceDoesNotExist: Path
(/Users/serge.smertin@databricks.com/.vMj0/state.json) doesn't exist.`
is not as clear as `databricks.sdk.errors.platform.ResourceDoesNotExist:
...`, where it's obvious errors are coming from the Databricks Platform.

<img width="807" alt="image"
src="https://github.com/databricks/databricks-sdk-py/assets/259697/390b8dc0-649d-44ce-89c1-4f36ef2e06ec">
  • Loading branch information
nfx authored Jan 31, 2024
1 parent 4cb9345 commit 1fcb270
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .codegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"batch": {
".codegen/__init__.py.tmpl": "databricks/sdk/__init__.py",
".codegen/error_mapping.py.tmpl": "databricks/sdk/errors/mapping.py"
".codegen/error_mapping.py.tmpl": "databricks/sdk/errors/platform.py"
},
"samples": {
".codegen/example.py.tmpl": "examples/{{.Service.SnakeName}}/{{.Method.SnakeName}}_{{.SnakeName}}.py"
Expand Down
2 changes: 1 addition & 1 deletion databricks/sdk/errors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .base import DatabricksError, ErrorDetail
from .mapper import error_mapper
from .mapping import *
from .platform import *
from .sdk import *
10 changes: 5 additions & 5 deletions databricks/sdk/errors/mapper.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from databricks.sdk.errors import mapping
from databricks.sdk.errors import platform
from databricks.sdk.errors.base import DatabricksError


def error_mapper(status_code: int, raw: dict) -> DatabricksError:
error_code = raw.get('error_code', None)
if error_code in mapping.ERROR_CODE_MAPPING:
if error_code in platform.ERROR_CODE_MAPPING:
# more specific error codes override more generic HTTP status codes
return mapping.ERROR_CODE_MAPPING[error_code](**raw)
return platform.ERROR_CODE_MAPPING[error_code](**raw)

if status_code in mapping.STATUS_CODE_MAPPING:
if status_code in platform.STATUS_CODE_MAPPING:
# more generic HTTP status codes matched after more specific error codes,
# where there's a default exception class per HTTP status code, and we do
# rely on Databricks platform exception mapper to do the right thing.
return mapping.STATUS_CODE_MAPPING[status_code](**raw)
return platform.STATUS_CODE_MAPPING[status_code](**raw)

# backwards-compatible error creation for cases like using older versions of
# the SDK on way never releases of the platform.
Expand Down
File renamed without changes.

0 comments on commit 1fcb270

Please sign in to comment.