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.

@jay23606
jay23606 force-pushed the fix/odc-cli-empty-error-body branch 2 times, most recently from 43692e6 to b8091df Compare October 21, 2026 05:12

@joshunrau joshunrau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for picking this up. The fix is right: I pointed the CLI at a server returning empty 502 and 405 responses, and it now prints the status and reason instead of a traceback. Three small things before it can go in:

  1. Commit message line length. The body of b8091df is a single 225-character line, and our Commitlint check rejects body lines longer than 100 characters (body-max-line-length). Please rewrap it across several lines. Keep the header as fix: ... with no scope: cli isn't a pnpm workspace, so a (odc-cli) or (cli) scope would fail the scope check.
  2. Comment at cli/odc-cli:218. Please remove it. It describes what the next two lines already say, and the repo convention is that comments only explain things the code can't.
  3. except (TypeError, ValueError) at cli/odc-cli:225. HTTPStatus(value) raises ValueError for anything that isn't a known status, including None and codes like 520, so TypeError can't happen here. Please narrow it to except ValueError.

If you hand this to Claude Code, Sonnet 5 is the right size — three small edits in one file plus rewording one commit.

Reviewed at commit b8091df.

@jay23606

Copy link
Copy Markdown
Author

Removed the redundant comment and narrowed the exception handler to ValueError. This round did not change any commit or push changes.

@jay23606

Copy link
Copy Markdown
Author

Removed the redundant comment and narrowed the exception handler to ValueError. The requested commit message update was not made in this round.

@jay23606
jay23606 force-pushed the fix/odc-cli-empty-error-body branch from 021757f to ad45ac0 Compare October 31, 2026 07:29
The CLI printed a traceback for empty 502 or 405 responses.

Every non-2xx response now has its statusCode; a non-object body

gets the standard reason phrase. The API body's statusCode wins.
@jay23606
jay23606 force-pushed the fix/odc-cli-empty-error-body branch from ad45ac0 to 4c3e246 Compare October 31, 2026 18:04

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

3 participants