Skip to content

fix: improve error handling when request receives non-JSON response#1477

Merged
NeilSmithDLS merged 10 commits intomainfrom
fix--improve-error-handling-when-request-receives-non-JSON-response
Apr 14, 2026
Merged

fix: improve error handling when request receives non-JSON response#1477
NeilSmithDLS merged 10 commits intomainfrom
fix--improve-error-handling-when-request-receives-non-JSON-response

Conversation

@NeilSmithDLS
Copy link
Copy Markdown
Contributor

improve error handling when request receives non-JSON response.

Closes 1472

@NeilSmithDLS NeilSmithDLS requested a review from a team as a code owner April 9, 2026 07:45
@NeilSmithDLS NeilSmithDLS requested a review from tpoliaw April 9, 2026 07:46
@NeilSmithDLS NeilSmithDLS marked this pull request as draft April 9, 2026 10:06
@NeilSmithDLS NeilSmithDLS marked this pull request as draft April 9, 2026 10:06
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.22%. Comparing base (774781b) to head (a6ad517).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1477      +/-   ##
==========================================
+ Coverage   95.21%   95.22%   +0.01%     
==========================================
  Files          43       43              
  Lines        3132     3144      +12     
==========================================
+ Hits         2982     2994      +12     
  Misses        150      150              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@NeilSmithDLS NeilSmithDLS force-pushed the fix--improve-error-handling-when-request-receives-non-JSON-response branch from 566bd02 to ba9a28b Compare April 9, 2026 13:29
@NeilSmithDLS NeilSmithDLS marked this pull request as ready for review April 10, 2026 11:04
Comment thread src/blueapi/client/rest.py
Copy link
Copy Markdown
Contributor

@tpoliaw tpoliaw left a comment

Choose a reason for hiding this comment

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

I'm not sure the _exception method is the best place for this check to be, for instance running a plan uses the alternative _create_task_exceptions method and bypasses this check

$ # with config pointing to oauth-proxy
$ uv run blueapi -c path/to/config.yaml controller run --bg -i cm12345-3 sleep '{"time": 3}'
Error: task could not run: Expecting value: line 1 column 1 (char 0)

We're also parsing the json multiple times on the happy path when everything is working which isn't ideal.

Would it work to add a helper method to wrap wherever we're calling .json()?

@NeilSmithDLS NeilSmithDLS force-pushed the fix--improve-error-handling-when-request-receives-non-JSON-response branch from 98a4f7c to 55f732f Compare April 13, 2026 08:59
Comment thread src/blueapi/client/rest.py Outdated
@NeilSmithDLS NeilSmithDLS requested a review from tpoliaw April 13, 2026 10:18
Copy link
Copy Markdown
Contributor

@tpoliaw tpoliaw left a comment

Choose a reason for hiding this comment

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

This is much better, thanks. A couple of more minor comments if you want to look at them but this is a big improvement over the stacktrace it gave before.

Comment thread src/blueapi/client/rest.py Outdated
Comment thread src/blueapi/client/rest.py
Comment thread src/blueapi/client/rest.py Outdated
@NeilSmithDLS NeilSmithDLS merged commit 9f15b40 into main Apr 14, 2026
18 checks passed
@NeilSmithDLS NeilSmithDLS deleted the fix--improve-error-handling-when-request-receives-non-JSON-response branch April 14, 2026 07:40
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.

BlueapiClient gives unhelpful error message when invalid JSON is returned

3 participants