From 30cd3202372ea5335f63314f44309375cbc99d2b Mon Sep 17 00:00:00 2001 From: Jaslin Date: Mon, 1 Dec 2025 00:56:12 -0500 Subject: [PATCH] Fix Issue #5635: improve SubsonicUpdate error messages when server is unavailable --- beetsplug/subsonicupdate.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/beetsplug/subsonicupdate.py b/beetsplug/subsonicupdate.py index 673cc94a8..e8ecb4c63 100644 --- a/beetsplug/subsonicupdate.py +++ b/beetsplug/subsonicupdate.py @@ -138,20 +138,29 @@ class SubsonicUpdate(BeetsPlugin): params=payload, timeout=10, ) - json = response.json() - + try: + json = response.json() + except ValueError: + self._log.error("Invalid JSON from Subsonic: {}", response.text[:200]) + return + resp = json.get("subsonic-response") + if not resp: + self._log.error("Missing 'subsonic-response' field: {}", json) + return + status = resp.get("status") if ( response.status_code == 200 - and json["subsonic-response"]["status"] == "ok" + and status == "ok" ): - count = json["subsonic-response"]["scanStatus"]["count"] + count = resp.get("scanStatus", {}).get("count", 0) self._log.info("Updating Subsonic; scanning {} tracks", count) elif ( response.status_code == 200 - and json["subsonic-response"]["status"] == "failed" + and status == "failed" ): + msg = resp.get("error", {}).get("message", "Unknown error") self._log.error( - "Error: {[subsonic-response][error][message]}", json + "Error: {}", msg ) else: self._log.error("Error: {}", json)