Skip to content

Include ResponseWrapper in APIError#1261

Merged
renaudhartert-db merged 2 commits into
mainfrom
denik/error-add-responsewrapper
Aug 7, 2025
Merged

Include ResponseWrapper in APIError#1261
renaudhartert-db merged 2 commits into
mainfrom
denik/error-add-responsewrapper

Conversation

@denik

@denik denik commented Aug 7, 2025

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

APIError includes ResponseWrapper field.

This allows for clients to generate their own error message that includes this critical bits:

  • method + full URL
  • HTTP status code

For more verbose modes:

  • HTTP status message
  • request/response headers
  • request/response bodies

I plan to use it in CLI/DABs, currently I'm annotating errors with endpoint name, I'd be able to get rid of this boilerplate: https://github.com/databricks/cli/blob/0a7bd1a/bundle/terranova/tnresources/job.go#L34-L36

How is this tested?

Updated existing unit tests to (partially) compare this new field.

@denik denik temporarily deployed to test-trigger-is August 7, 2025 12:08 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is August 7, 2025 12:09 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is August 7, 2025 12:27 — with GitHub Actions Inactive
@github-actions

github-actions Bot commented Aug 7, 2025

Copy link
Copy Markdown

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/sdk-go

Inputs:

  • PR number: 1261
  • Commit SHA: 86d67bc6194654619345828bd521eccc3065ec1b

Checks will be approved automatically on success.

@denik denik temporarily deployed to test-trigger-is August 7, 2025 12:28 — with GitHub Actions Inactive
@renaudhartert-db renaudhartert-db added this pull request to the merge queue Aug 7, 2025
Merged via the queue into main with commit 7445841 Aug 7, 2025
15 checks passed
@renaudhartert-db renaudhartert-db deleted the denik/error-add-responsewrapper branch August 7, 2025 13:01
denik added a commit to databricks/cli that referenced this pull request Aug 7, 2025
denik added a commit to databricks/cli that referenced this pull request Aug 7, 2025
@denik

denik commented Aug 7, 2025

Copy link
Copy Markdown
Contributor Author

Thanks! This is CLI integration: databricks/cli#3379 that shows how we going to use that:

Error: deploying jobs.foo: creating: Shared job cluster feature is only supported in multi-task jobs. (400 INVALID_PARAMETER_VALUE)

Endpoint: POST [DATABRICKS_URL]/api/2.2/jobs/create
HTTP Status: 400 Bad Request
API error_code: INVALID_PARAMETER_VALUE
API message: Shared job cluster feature is only supported in multi-task jobs.

denik added a commit to databricks/cli that referenced this pull request Aug 7, 2025
denik added a commit to databricks/cli that referenced this pull request Aug 8, 2025
denik added a commit to databricks/cli that referenced this pull request Aug 14, 2025
denik added a commit to databricks/cli that referenced this pull request Aug 18, 2025
denik added a commit to databricks/cli that referenced this pull request Aug 18, 2025
github-merge-queue Bot pushed a commit to databricks/cli that referenced this pull request Aug 18, 2025
…iagnostics (#3379)

## Changes
- Any API error passed to diag.FromErr or logdiag.LogError will
automatically be formatted to include HTTP status/message, HTTP method +
full url, API code and message.
- Custom error from direct deployment is removed, it's no longer needed.

## Why
SDK errors by default only contain "message" from payload which
sometimes looks like this "Request 123 failed".
DABs/CLI do not add a lot of context to errors, so that message is all
you see.
This makes debugging very hard. I've been fixing this in direct
deployment by
- adding context to errors everywhere
- tagging errors with endpoint

This PR makes tagging unnecessary and adds better error handling to all
of CLI - as long as you use logdiag.LogError, it'll add those critical
details, see create-error test for example of the output.

Requires databricks/databricks-sdk-go#1261

## Tests
Existing tests.
denik added a commit to databricks/cli that referenced this pull request May 20, 2026
…iagnostics (#3379)

## Changes
- Any API error passed to diag.FromErr or logdiag.LogError will
automatically be formatted to include HTTP status/message, HTTP method +
full url, API code and message.
- Custom error from direct deployment is removed, it's no longer needed.

## Why
SDK errors by default only contain "message" from payload which
sometimes looks like this "Request 123 failed".
DABs/CLI do not add a lot of context to errors, so that message is all
you see.
This makes debugging very hard. I've been fixing this in direct
deployment by
- adding context to errors everywhere
- tagging errors with endpoint

This PR makes tagging unnecessary and adds better error handling to all
of CLI - as long as you use logdiag.LogError, it'll add those critical
details, see create-error test for example of the output.

Requires databricks/databricks-sdk-go#1261

## Tests
Existing tests.
denik pushed a commit to databricks/cli that referenced this pull request May 20, 2026
The reverse proxy in `libs/testproxy` re-marshalled `apierr.APIError`
into a `{error_code, message}` envelope, dropping `details[]` and any
other fields the workspace returned. As a result, acceptance tests run
against the cloud could not observe error metadata that real CLI/TF
invocations rely on.

This change forwards `apiErr.ResponseWrapper.DebugBytes` verbatim with
the original status code, so callers see exactly what the workspace
sent. As a knock-on fix, response headers in `includeResponseHeaders`
(e.g. `X-Databricks-Org-Id`) are now also passed through on the error
path — previously the `WithResponseHeader` visitors weren't invoked when
`apiClient.Do` returned an error.

`ResponseWrapper` has been populated on every `APIError` since
[databricks-sdk-go#1261](databricks/databricks-sdk-go#1261)
(v0.100.0); the CLI is on v0.132.0. A panic guards the invariant in case
the SDK ever changes shape.
bernardo-rodriguez pushed a commit to bernardo-rodriguez/b-cli that referenced this pull request May 21, 2026
…ks#5263)

The reverse proxy in `libs/testproxy` re-marshalled `apierr.APIError`
into a `{error_code, message}` envelope, dropping `details[]` and any
other fields the workspace returned. As a result, acceptance tests run
against the cloud could not observe error metadata that real CLI/TF
invocations rely on.

This change forwards `apiErr.ResponseWrapper.DebugBytes` verbatim with
the original status code, so callers see exactly what the workspace
sent. As a knock-on fix, response headers in `includeResponseHeaders`
(e.g. `X-Databricks-Org-Id`) are now also passed through on the error
path — previously the `WithResponseHeader` visitors weren't invoked when
`apiClient.Do` returned an error.

`ResponseWrapper` has been populated on every `APIError` since
[databricks-sdk-go#1261](databricks/databricks-sdk-go#1261)
(v0.100.0); the CLI is on v0.132.0. A panic guards the invariant in case
the SDK ever changes shape.
TanishqDatabricks pushed a commit to TanishqDatabricks/cli that referenced this pull request May 22, 2026
…ks#5263)

The reverse proxy in `libs/testproxy` re-marshalled `apierr.APIError`
into a `{error_code, message}` envelope, dropping `details[]` and any
other fields the workspace returned. As a result, acceptance tests run
against the cloud could not observe error metadata that real CLI/TF
invocations rely on.

This change forwards `apiErr.ResponseWrapper.DebugBytes` verbatim with
the original status code, so callers see exactly what the workspace
sent. As a knock-on fix, response headers in `includeResponseHeaders`
(e.g. `X-Databricks-Org-Id`) are now also passed through on the error
path — previously the `WithResponseHeader` visitors weren't invoked when
`apiClient.Do` returned an error.

`ResponseWrapper` has been populated on every `APIError` since
[databricks-sdk-go#1261](databricks/databricks-sdk-go#1261)
(v0.100.0); the CLI is on v0.132.0. A panic guards the invariant in case
the SDK ever changes shape.
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