Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Handle non-JSON errors #1031

Merged
merged 5 commits into from
Aug 29, 2024
Merged

[Fix] Handle non-JSON errors #1031

merged 5 commits into from
Aug 29, 2024

Conversation

mgyucht
Copy link
Contributor

@mgyucht mgyucht commented Aug 29, 2024

Changes

Some errors returned by the platform are not serialized using JSON (see #998 for an example). They are instead serialized in the form "<ERROR_CODE>: ". Today, the SDK cannot parse these error messages well, resulting in a poor user experience.

This PR adds support for parsing these error messages from the platform to the SDK. This should reduce bug reports for the SDK with respect to unexpected response parsing. This PR also refactors the error deserialization logic somewhat to make it more extensible in the future for other potential error formats that are not currently handled.

Breaking Changes

This PR renames MakeUnexpectedError() to MakeUnexpectedResponse() in the apierr package. It also changes the return type to string. This makes the message easier to incorporate into error responses that only depend on the string representation of the error, as well as allows us to start the message with a capital letter, as it is a complete sentence.

The error message for failed deserialization of valid responses has changed slightly, from unexpected error handling request to failed to unmarshal response body. The rest of the message is identical.

Tests

Refactored unit tests to a table-driven test case, and added four new cases: one for error details (not previously covered), one for the regular happy path, one for unexpected responses, and one for the new error message format.

  • make test passing
  • make fmt applied
  • relevant integration tests applied

@mgyucht mgyucht marked this pull request as ready for review August 29, 2024 10:43
Copy link
Contributor

@renaudhartert-db renaudhartert-db left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No concern about the logic, left a few nit comments.

apierr/errors.go Outdated Show resolved Hide resolved
apierr/errors.go Outdated Show resolved Hide resolved
apierr/errors.go Outdated Show resolved Hide resolved
mgyucht and others added 3 commits August 29, 2024 13:40
Copy link
Contributor

@renaudhartert-db renaudhartert-db left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mgyucht mgyucht added this pull request to the merge queue Aug 29, 2024
Merged via the queue into main with commit 796dae1 Aug 29, 2024
8 checks passed
@mgyucht mgyucht deleted the handle-non-json-errors branch August 29, 2024 15:08
github-merge-queue bot pushed a commit to databricks/databricks-sdk-py that referenced this pull request Aug 30, 2024
## Changes
Some errors returned by the platform are not serialized using JSON (see
databricks/databricks-sdk-go#998 for an
example). They are instead serialized in the form "<ERROR_CODE>:
<MESSAGE>". Today, the SDK cannot parse these error messages well,
resulting in a poor user experience.

This PR adds support for parsing these error messages from the platform
to the SDK. This should reduce bug reports for the SDK with respect to
unexpected response parsing. This PR also refactors the error
deserialization logic somewhat to make it more extensible in the future
for other potential error formats that are not currently handled.

As a side-effect of this change, I've refactored the structure of the
error handling in the Python SDK to more closely reflect how errors are
handled in the Go SDK. This should make maintenance more straightforward
in the future. It also introduces a new error message to the Python SDK
to refer users to our issue tracker when the SDK receives an error
response that it cannot parse, like what we do in the Go SDK.

Ports databricks/databricks-sdk-go#1031 to the
Python SDK.

## Deprecations
This PR deprecates several fields in the constructor for
DatabricksError. Going forward, SCIM-specific and API 1.2-specific
parameters should not be specified in the constructor; instead, they
will be handled in error parsers.

## Breaking Changes
The introduction of a different message for non-JSON responses may be a
breaking change if users matched on the message structure used before.

## Tests
Existing tests still pass, adding tests before merging this.

- [ ] `make test` run locally
- [ ] `make fmt` applied
- [ ] relevant integration tests applied
mgyucht added a commit that referenced this pull request Sep 4, 2024
### Bug Fixes

 * Fail fast when authenticating if host is not configured ([#1033](#1033)).
 * Improve non-JSON error handling ([#1031](#1031)).

### Internal Changes

 * Add TestAccCreateOboTokenOnAws to flaky test list ([#1029](#1029)).
 * Add workflows manage integration tests checks ([#1032](#1032)).
 * Fix TestMwsAccWorkspaces cleanup ([#1028](#1028)).
 * Improve integration test comment ([#1035](#1035)).
 * Temporary ignore Metastore test failures ([#1027](#1027)).
 * Update test to support new accounts ([#1026](#1026)).
 * Use statuses instead of checks ([#1036](#1036)).

### API Changes:

 * Added `RegenerateDashboard` method for [w.QualityMonitors](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/catalog#QualityMonitorsAPI) workspace-level service.
 * Added [catalog.RegenerateDashboardRequest](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/catalog#RegenerateDashboardRequest) and [catalog.RegenerateDashboardResponse](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/catalog#RegenerateDashboardResponse).
 * Added [jobs.QueueDetails](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#QueueDetails), [jobs.QueueDetailsCodeCode](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#QueueDetailsCodeCode), [jobs.RunLifecycleStateV2State](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#RunLifecycleStateV2State), [jobs.RunStatus](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#RunStatus), [jobs.TerminationCodeCode](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#TerminationCodeCode), [jobs.TerminationDetails](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#TerminationDetails) and [jobs.TerminationTypeType](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#TerminationTypeType).
 * Added `Status` field for [jobs.BaseRun](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#BaseRun).
 * Added `Status` field for [jobs.RepairHistoryItem](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#RepairHistoryItem).
 * Added `Status` field for [jobs.Run](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#Run).
 * Added `Status` field for [jobs.RunTask](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#RunTask).
 * Added `MaxProvisionedThroughput` and `MinProvisionedThroughput` fields for [serving.ServedModelInput](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServedModelInput).
 * Added `ColumnsToSync` field for [vectorsearch.DeltaSyncVectorIndexSpecRequest](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/vectorsearch#DeltaSyncVectorIndexSpecRequest).
 * Changed `WorkloadSize` field for [serving.ServedModelInput](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServedModelInput) to no longer be required.

OpenAPI SHA: d05898328669a3f8ab0c2ecee37db2673d3ea3f7, Date: 2024-09-04
github-merge-queue bot pushed a commit that referenced this pull request Sep 4, 2024
### Bug Fixes

* Fail fast when authenticating if host is not configured
([#1033](#1033)).
* Improve non-JSON error handling
([#1031](#1031)).


### Internal Changes

* Add TestAccCreateOboTokenOnAws to flaky test list
([#1029](#1029)).
* Add workflows manage integration tests checks
([#1032](#1032)).
* Fix TestMwsAccWorkspaces cleanup
([#1028](#1028)).
* Improve integration test comment
([#1035](#1035)).
* Temporary ignore Metastore test failures
([#1027](#1027)).
* Update test to support new accounts
([#1026](#1026)).
* Use statuses instead of checks
([#1036](#1036)).


### API Changes:

* Added `RegenerateDashboard` method for
[w.QualityMonitors](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/catalog#QualityMonitorsAPI)
workspace-level service.
* Added
[catalog.RegenerateDashboardRequest](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/catalog#RegenerateDashboardRequest)
and
[catalog.RegenerateDashboardResponse](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/catalog#RegenerateDashboardResponse).
* Added
[jobs.QueueDetails](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#QueueDetails),
[jobs.QueueDetailsCodeCode](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#QueueDetailsCodeCode),
[jobs.RunLifecycleStateV2State](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#RunLifecycleStateV2State),
[jobs.RunStatus](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#RunStatus),
[jobs.TerminationCodeCode](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#TerminationCodeCode),
[jobs.TerminationDetails](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#TerminationDetails)
and
[jobs.TerminationTypeType](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#TerminationTypeType).
* Added `Status` field for
[jobs.BaseRun](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#BaseRun).
* Added `Status` field for
[jobs.RepairHistoryItem](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#RepairHistoryItem).
* Added `Status` field for
[jobs.Run](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#Run).
* Added `Status` field for
[jobs.RunTask](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/jobs#RunTask).
* Added `MaxProvisionedThroughput` and `MinProvisionedThroughput` fields
for
[serving.ServedModelInput](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServedModelInput).
* Added `ColumnsToSync` field for
[vectorsearch.DeltaSyncVectorIndexSpecRequest](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/vectorsearch#DeltaSyncVectorIndexSpecRequest).
* Changed `WorkloadSize` field for
[serving.ServedModelInput](https://pkg.go.dev/github.com/databricks/databricks-sdk-go/service/serving#ServedModelInput)
to no longer be required.

OpenAPI SHA: d05898328669a3f8ab0c2ecee37db2673d3ea3f7, Date: 2024-09-04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants