Skip to content

fix(odc-cli): report the status for an error response with an empty body - #1809

Open
jay23606 wants to merge 1 commit into
DouglasNeuroInformatics:mainfrom
jay23606:fix/odc-cli-empty-error-body
Open

jay23606 wants to merge 1 commit into
DouglasNeuroInformatics:mainfrom
jay23606:fix/odc-cli-empty-error-body

Conversation

@jay23606

Copy link
Copy Markdown

Fixes #1779

Summary

  • `HttpResponse.to_json` merged the body into the output with `props.update(**self.data)` on a non-2xx status. An empty error body is stored as `data=None`, so the CLI crashed with `TypeError: dict.update() argument after ** must be a mapping, not NoneType`.
  • When the error body is not an object, the output now carries the `statusCode`. Object bodies are merged as before.

Test

  • `cli/` has no test harness, and AGENTS.md says nothing checks it on a pull request, so I verified it by loading the script directly:
    • `HttpResponse(data=None, status=502).to_json(include_data=False)` gives `{"statusCode": 502}`. The original script raises the `TypeError`.
    • An object error body still merges its fields as before.
  • Not run: the rest of the repo's checks, which do not cover `cli/`.

🤖 Generated with Claude Code

@jay23606
jay23606 requested a review from joshunrau as a code owner October 12, 2026 22:23

@gdevenyi gdevenyi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for this fix. The crash is gone: I ran the CLI against a server that returns an empty 502, and it now prints {"statusCode": 502} instead of the traceback. Two changes are necessary before we can merge:

  1. The commit scope fails Commitlint. fix(odc-cli): ... uses the scope odc-cli, but commitlint.config.ts accepts only workspace names in scope-enum, and cli/ is not a pnpm workspace. The Commitlint CI job will fail on this commit. Please reword it to fix: report the status for an error response with an empty body (no scope) and force-push.

  2. The status code is still lost for an error body that is an object. In cli/odc-cli:216-221, statusCode is added only when the body is not a dict. A proxy that returns 502 with an HTML body goes through _build_response, which stores {'error': 'Invalid JSON response'}. That is a dict, so the output is {"error": "Invalid JSON response"} with no status. Issue #1779 asks for statusCode on every failure. Please set props['statusCode'] = self.status or 'N/A' for every non-2xx response, then merge self.data on top when it is a dict, so an API body that has its own statusCode still wins. For a body that is not a dict, also add error from http.HTTPStatus(self.status).phrase (catch ValueError for a status code that is not standard), so the output matches the expected {"statusCode": 405, "error": "Method Not Allowed"} in the issue. http is in the standard library and works on Python 3.8.

If you hand this to Claude Code, Sonnet 5 is the right size, because the change is in one file and the items above specify all of it.

Reviewed at commit 4dbfdae.

The CLI printed a traceback for an empty 502 or 405 response. Every
non-2xx response now carries its statusCode, and a non-object body
gets the standard reason phrase as error. An API body with its own
statusCode still wins.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
@jay23606
jay23606 force-pushed the fix/odc-cli-empty-error-body branch from 4dbfdae to 43692e6 Compare October 14, 2026 21:35

This branch has not been deployed

No deployments
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.

odc-cli crashes with a TypeError traceback when an error response has an empty body

2 participants