Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open Beginner friendly
#1,779 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
cli

Research direction

Read cli/odc-cli around lines 210–218 and 276–279 to follow how empty response bodies reach HttpResponse.to_json. The CLI has no test harness, so verify with a server returning an empty-body 502, as described in the issue. Done when setup get-state and auth login print a JSON error instead of a traceback.

Written by the indexing model from the issue text.

Description

Area: Infrastructure Bug Difficulty: Low Good First Issue Priority: Low

odc-cli crashes with a Python traceback whenever the server answers with an error status and an empty body, so the admin never sees the status code. HttpClient._build_response stores data=None for an empty body. On a non-2xx status, HttpResponse.to_json then runs props.update(**self.data), which raises TypeError when data is None. Two common situations produce an empty error body. The bundled Caddy returns 502 with no body while the api container is restarting. The web container's Caddy returns 405 with no body when the configured base URL is the site root instead of …/api, which is an easy mistake because the web app and the API share one origin. In both cases the admin gets a traceback about dict.update() instead of the status code and a hint.

Where

cli/odc-cli:210-218:

def to_json(self, include_data: bool) -> str:
    props: dict[str, Any] = {}
    if self.ok:
        # ...
    elif not self.ok:
        props.update(**self.data)
    return to_json(props)

cli/odc-cli:276-279:

body = response.read()
if not body:
    return HttpResponse(data=None, status=response.getcode())

Reproduce

  1. With the compose stack running, run odc-cli config set-url http://localhost:5500, without the /api suffix.
  2. Run odc-cli auth login --username admin --password-stdin.

Actual (verified against caddy:2.7-alpine with apps/web/Caddyfile, which answers 405 Method Not Allowed, Content-Length: 0):

  File "cli/odc-cli", line 217, in to_json
    props.update(**self.data)
TypeError: dict.update() argument after ** must be a mapping, not NoneType

The same traceback appears for any command while Caddy is returning an empty 502.
Expected: a JSON error such as {"statusCode": 405, "error": "Method Not Allowed"}, as for any other failed request.

Tests

cli/ has no test harness (cli/AGENTS.md). Verify the fix by pointing the CLI at a server that returns 502 with Content-Length: 0, for example a three-line http.server handler, and checking that setup get-state and auth login print a JSON error instead of a traceback.

Suggested fix

In to_json, include statusCode for failures too, and merge self.data only when it is a dict. Otherwise add error taken from http.HTTPStatus(self.status).phrase.

Dominant language
TypeScript
Stars
119
Forks
19
Avg merge
1d 2h
Merged PRs (30d)
56

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DouglasNeuroInformatics/OpenDataCapture

All issues in DouglasNeuroInformatics/OpenDataCapture

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.