Skip to content

Surface the API's error detail when a dataset import fails - #38

Open
Anupma110 wants to merge 1 commit into
mainfrom
bugfix/714769-byod-error-detail
Open

Anupma110 wants to merge 1 commit into
mainfrom
bugfix/714769-byod-error-detail

Conversation

@Anupma110

Copy link
Copy Markdown
Collaborator

Problem

Gateway.import_dataset parsed the error response only to pull out traceId and discarded everything else, so a failed DataCatalogue.save(...) told the user:

Failed to create data catalog entry. correlation-id: 8b01e7eb14484611add6138618daf112

The API already returns a ProblemDetails body explaining the failure (detail, title, per-field errors) — none of it reached the caller, who had to ask someone to look up the trace before they could act.

There was also a second failure mode: _get_trace_id_from_response called json.loads(response.text) unguarded. When a gateway or proxy answered with HTML (e.g. a 502), that raised JSONDecodeError inside the except block, replacing the real error with a parse error.

Change

The raised error now carries the reason the API gave, with the correlation id kept at the end:

Response Before After
ProblemDetails with detail …correlation-id: 0af412aa… …: Ensure DatasetName is unique when creating Predefined Dataset. (correlation-id: 0af412aa…)
Validation errors …correlation-id: abc …: BadRequest
datasetName: must not be empty; schemaId: not found (correlation-id: abc)
Non-JSON body (502) raised JSONDecodeError …: HTTP 502: <html>…502 Bad Gateway…</html>

JSON parsing is now tolerant, and a non-JSON body degrades to the status code plus a short excerpt rather than masking the failure.

Tests

5 new tests in tests/test_gateway.py covering detail, per-field errors, title fallback, a non-JSON body, and a connection error with no response at all.

The existing test_import_dataset_failure asserted the old exact string, so it now asserts the correlation id is still present rather than pinning the message.

Suite: 45 → 50 passing.

The failure path read the response body only to pull out traceId and threw the
rest away, so a caller was told nothing beyond a correlation id and had to ask
someone to look up the trace before they could act.

The raised error now carries the reason the API gave: the ProblemDetails detail
or title, plus any per-field validation errors, with the correlation id kept at
the end.

Parsing is also no longer assumed to succeed. A gateway answering with HTML made
json.loads raise inside the except block, replacing the real failure with a
JSONDecodeError; a non-JSON body now degrades to the status code and a short
excerpt.
Copilot AI lite review requested due to automatic review settings September 18, 2026 14:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The no-response error path loses actionable exception details, and the fallback excerpt needs stronger test coverage.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Improves dataset import failures by surfacing API error details and safely handling non-JSON responses.

Changes:

  • Formats ProblemDetails and validation errors.
  • Preserves correlation IDs and adds fallback descriptions.
  • Adds coverage for API, proxy, and connection failures.
File summaries
File Summary Review feedback
src/dataworkbench/gateway.py Formats and surfaces detailed import failures. Moderate (2 votes): Preserve the original exception text when no response is available.
tests/test_gateway.py Tests detailed, validation, fallback, and connection errors. Nit (1 vote): Assert the non-JSON fallback includes 502 Bad Gateway.
Review details

Suppressed comments (1)

tests/test_gateway.py:129

  • This assertion only checks the status code, so the test would still pass if the non-JSON fallback regressed to HTTP 502 and dropped the body excerpt promised by the new implementation. Assert that 502 Bad Gateway is also present to cover the excerpt behavior.
    assert "502" in e.value.args[0]
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +197 to 198
f"Failed to create data catalog entry: {_describe_failure(e.response)}"
)
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.

3 participants