fix(decisioning): project malformed-JSON 2xx responses to AdcpError#767
Draft
bokelley wants to merge 2 commits into
Draft
fix(decisioning): project malformed-JSON 2xx responses to AdcpError#767bokelley wants to merge 2 commits into
bokelley wants to merge 2 commits into
Conversation
Catches JSONDecodeError from upstream.py's _request method and raises a typed AdcpError(SERVICE_UNAVAILABLE, recovery="transient") so adopters get a structured error rather than a raw decode exception when a proxy or CDN returns an HTML error page with a 200 status. Closes #453 https://claude.ai/code/session_0172h7dGLvfEeo1DLKzAH4TZ
Tightens the catch in UpstreamHttpClient._request from bare Exception to ValueError (which covers json.JSONDecodeError and any custom decoder that signals parse failure the same way), matching the narrower defensive pattern used elsewhere in the file. Adds __cause__ assertion to the test. https://claude.ai/code/session_0172h7dGLvfEeo1DLKzAH4TZ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #453
The
create_upstream_http_clientandcreate_translation_maphelpers were already fully implemented and exported fromadcp.decisioning. This PR closes the one remaining acceptance-criteria gap: JSON decode errors.When an upstream returns a successful (2xx) status with a non-JSON body (e.g. a CDN or proxy returns an HTML error page),
UpstreamHttpClient._requestpreviously propagated a rawjson.JSONDecodeErrorfromresponse.json(). Adopters catchAdcpErrorthroughout; an unhandledValueErrorsubclass breaks that contract and is invisible in typed code. This PR wraps the call inexcept ValueErrorand re-raises asAdcpError(SERVICE_UNAVAILABLE, recovery="transient")— the same code used for 5xx responses, since an upstream returning HTML for a JSON endpoint is indistinguishable from a transient infrastructure failure.What changed
src/adcp/decisioning/upstream.py: wrapresponse.json()intry/except ValueError; raiseAdcpError(SERVICE_UNAVAILABLE)withrecovery="transient"andfrom excchain.tests/test_upstream_helpers.py: addtest_200_with_malformed_json_raises_service_unavailable— mocks a 200 with an HTML body and asserts code, recovery, and__cause__.What tested
uv run pytest tests/test_upstream_helpers.py tests/test_upstream_for.py -q— 57 passed, 0 faileduv run mypy src/adcp/decisioning/upstream.py— cleanuv run ruff check src/adcp/decisioning/upstream.py tests/test_upstream_helpers.py— cleanPre-PR review
except Exception→except ValueError;__cause__assertion added to test)Nits (not fixed):
await client.aclose()in the new test is not in afinallyblock; consistent with the rest of the file's existing test style — test-only resource leak onlyexctext rather than a body-length hint; useful for debugging, acceptableSession: https://claude.ai/code/session_0172h7dGLvfEeo1DLKzAH4TZ
Generated by Claude Code