odc-cli crashes with a TypeError traceback when an error response has an empty body
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 85/100
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
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
- With the compose stack running, run
odc-cli config set-url http://localhost:5500, without the/apisuffix. - 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
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from DouglasNeuroInformatics/OpenDataCapture
-
Area: Playground Bug Difficulty: Low Good First Issue Priority: Low
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
DouglasNeuroInformatics/OpenDataCapture#1805 ·
Maintainers usually reply within 1 day
-
Area: Instruments Bug Difficulty: Low Priority: Low
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
DouglasNeuroInformatics/OpenDataCapture#1801 ·
Maintainers usually reply within 1 day
-
Area: Instruments Bug Difficulty: Low Good First Issue Priority: Low
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
DouglasNeuroInformatics/OpenDataCapture#1800 ·
Maintainers usually reply within 1 day
-
Area: Instruments Bug Difficulty: Low Good First Issue Priority: Low
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
DouglasNeuroInformatics/OpenDataCapture#1799 ·
Maintainers usually reply within 1 day
-
Area: Instruments Bug Difficulty: Low Performance Priority: Medium
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
DouglasNeuroInformatics/OpenDataCapture#1795 ·
Maintainers usually reply within 1 day
All issues in DouglasNeuroInformatics/OpenDataCapture
Similar issues
-
Tenant
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
MTES-MCT/Dossier-Facile-Frontend#2061 ·
Maintainers usually reply within 1 day
-
area:frontend
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
interledger/publisher-tools#905 ·
Maintainers usually reply within 1 day
-
Add: Cbeebies PL SDOpenapproved check:passed streams:add
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
iptv-org/iptv#54525 · 1 comment ·
Maintainers usually reply within 1 day
-
DB-plane provider_chat_options.* is accepted by config set but never merged into the loaded configPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
area:web
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
praetorianer777/GoTome#178 ·
Maintainers usually reply within 1 day