-
Notifications
You must be signed in to change notification settings - Fork 2k
Improves SubsonicUpdate error messages when server is unavailable #5635 #6197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- When logging a missing 'subsonic-response' field, consider truncating or summarizing the JSON payload (similar to the invalid JSON case) to avoid excessively large log entries for big responses.
- Using
resp.get("scanStatus", {}).get("count", 0)silently falls back to 0 whenscanStatusorcountis missing; it may be more helpful to log a warning or treat this as an error so that unexpected server responses are visible rather than hidden.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- When logging a missing 'subsonic-response' field, consider truncating or summarizing the JSON payload (similar to the invalid JSON case) to avoid excessively large log entries for big responses.
- Using `resp.get("scanStatus", {}).get("count", 0)` silently falls back to 0 when `scanStatus` or `count` is missing; it may be more helpful to log a warning or treat this as an error so that unexpected server responses are visible rather than hidden.
## Individual Comments
### Comment 1
<location> `beetsplug/subsonicupdate.py:141-145` </location>
<code_context>
+ try:
+ json = response.json()
+ except ValueError:
+ self._log.error("Invalid JSON from Subsonic: {}", response.text[:200])
+ return
+ resp = json.get("subsonic-response")
</code_context>
<issue_to_address>
**suggestion:** Consider including the HTTP status code when logging invalid JSON responses.
The current log only shows a truncated body, which makes it hard to tell transient HTML error pages from truly malformed JSON. Logging `response.status_code` (and optionally the URL) alongside the body would make these issues easier to diagnose without adding much log noise.
```suggestion
try:
json = response.json()
except ValueError:
self._log.error(
"Invalid JSON from Subsonic (status {} for {}): {}",
response.status_code,
getattr(response, "url", "<unknown-url>"),
response.text[:200],
)
return
```
</issue_to_address>
### Comment 2
<location> `docs/changelog.rst:34-35` </location>
<code_context>
Bug fixes:
-
+- :doc:`plugins/subsonicupdate`: Improve error messages when the Subsonic server
+ is unavailable or returns invalid/missing JSON. Previously, failures were
+ cryptic (e.g., "Expecting value: line 1 column 1 (char 0)"). :bug:`5635`
- :doc:`plugins/inline`: Fix recursion error when an inline field definition
</code_context>
<issue_to_address>
**suggestion (typo):** Clarify the phrasing "invalid/missing JSON".
Consider changing this to `invalid or missing JSON` for clearer, more formal wording while preserving the meaning.
```suggestion
- :doc:`plugins/subsonicupdate`: Improve error messages when the Subsonic server
- is unavailable or returns invalid or missing JSON. Previously, failures were
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| try: | ||
| json = response.json() | ||
| except ValueError: | ||
| self._log.error("Invalid JSON from Subsonic: {}", response.text[:200]) | ||
| return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider including the HTTP status code when logging invalid JSON responses.
The current log only shows a truncated body, which makes it hard to tell transient HTML error pages from truly malformed JSON. Logging response.status_code (and optionally the URL) alongside the body would make these issues easier to diagnose without adding much log noise.
| try: | |
| json = response.json() | |
| except ValueError: | |
| self._log.error("Invalid JSON from Subsonic: {}", response.text[:200]) | |
| return | |
| try: | |
| json = response.json() | |
| except ValueError: | |
| self._log.error( | |
| "Invalid JSON from Subsonic (status {} for {}): {}", | |
| response.status_code, | |
| getattr(response, "url", "<unknown-url>"), | |
| response.text[:200], | |
| ) | |
| return |
docs/changelog.rst
Outdated
| - :doc:`plugins/subsonicupdate`: Improve error messages when the Subsonic server | ||
| is unavailable or returns invalid/missing JSON. Previously, failures were |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (typo): Clarify the phrasing "invalid/missing JSON".
Consider changing this to invalid or missing JSON for clearer, more formal wording while preserving the meaning.
| - :doc:`plugins/subsonicupdate`: Improve error messages when the Subsonic server | |
| is unavailable or returns invalid/missing JSON. Previously, failures were | |
| - :doc:`plugins/subsonicupdate`: Improve error messages when the Subsonic server | |
| - is unavailable or returns invalid or missing JSON. Previously, failures were |
semohr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR and initiative!
Since this seems to be your first contribution you might want to checkout our contribution guide. We are happy to have you onboard!
I’ve left a few comments that should help improve this PR.
beetsplug/subsonicupdate.py
Outdated
| except ValueError: | ||
| self._log.error("Invalid JSON from Subsonic: {}", response.text[:200]) | ||
| return | ||
| resp = json.get("subsonic-response") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The can be simplified to:
if not (resp := json.get("subsonic-response")):
self._log.error("Missing 'subsonic-response' field: {}", json)
return| params=payload, | ||
| timeout=10, | ||
| ) | ||
| json = response.json() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically we should do response.raise_for_status() here and handle errors properly in the try expect block below. Should also allow us to remove the if ( response.status_code == 200) conditional.
| if not resp: | ||
| self._log.error("Missing 'subsonic-response' field: {}", json) | ||
| return | ||
| status = resp.get("status") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have to be defensive here? The same applies to resp.get("scanStatus", {}).get("count", 0) below.
ef8dd5a to
6e08aa0
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6197 +/- ##
==========================================
- Coverage 67.93% 67.90% -0.03%
==========================================
Files 137 137
Lines 18677 18687 +10
Branches 3155 3156 +1
==========================================
+ Hits 12688 12690 +2
- Misses 5324 5330 +6
- Partials 665 667 +2
🚀 New features to boost your workflow:
|
Description
Fixes #5635: subsonicupdate fails cryptically when server is not available
The plugin previously produced unhelpful JSON-parsing errors when the server was down or returned unexpected data. This PR improves the error handling so that these situations now produce clear, user-friendly messages instead of cryptic failures such as:
This update adds explicit handling for:
Mocked Subsonic responses confirm the improved behavior:
These changes ensure that subsonicupdate failures are now clearly reported and no longer cryptic.
docs/changelog.rst.)