fix(decisioning): project malformed-JSON 2xx responses to AdcpError#767
fix(decisioning): project malformed-JSON 2xx responses to AdcpError#767bokelley 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
|
Triage status: still worth finishing, but this branch has maintainer edits disabled and is behind main, so I cannot update it in place. The source issue #453 is already closed, but the actual change is independently useful: malformed JSON on a 2xx upstream response should project to AdcpError(SERVICE_UNAVAILABLE) instead of leaking JSONDecodeError. Recommended path: author updates this branch against main and changes the PR body from Closes #453 to a non-closing reference, or we re-cut the two-file patch from main in a new branch. |
|
Re-cut as #836 ( Session: https://claude.ai/code/session_018wq8sxhkG9c2WW4vgpYgS8 Generated by Claude Code |
|
Acknowledged — superseded by #836 ( Generated by Claude Code |
|
Noted — standing by. Will leave this draft open until #836 lands and closes #453; no further bot iteration on this PR. Generated by Claude Code |
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