From 30cd3202372ea5335f63314f44309375cbc99d2b Mon Sep 17 00:00:00 2001 From: Jaslin Date: Mon, 1 Dec 2025 00:56:12 -0500 Subject: [PATCH 1/6] 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) From 6e08aa0276b6e3f49b49581a8812a8bb44b4473d Mon Sep 17 00:00:00 2001 From: Jaslin Date: Mon, 1 Dec 2025 02:14:59 -0500 Subject: [PATCH 2/6] Add changelog entry for #5635 subsonicupdate error messages --- docs/changelog.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index b9a5c1f3f..82783ce0d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -33,7 +33,9 @@ New features: resolve differences in metadata source styles. 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 shadows a built-in item field (e.g., redefining ``track_no``). Inline expressions now skip self-references during evaluation to avoid infinite From a81456a12c06bb874717944d7185e4f1cde47ea4 Mon Sep 17 00:00:00 2001 From: Jaslin Date: Thu, 4 Dec 2025 11:36:46 -0500 Subject: [PATCH 3/6] Apply formatting and fix lint issues --- beetsplug/subsonicupdate.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/beetsplug/subsonicupdate.py b/beetsplug/subsonicupdate.py index e8ecb4c63..ace5546f4 100644 --- a/beetsplug/subsonicupdate.py +++ b/beetsplug/subsonicupdate.py @@ -141,27 +141,21 @@ class SubsonicUpdate(BeetsPlugin): try: json = response.json() except ValueError: - self._log.error("Invalid JSON from Subsonic: {}", response.text[:200]) + 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 status == "ok" - ): + if response.status_code == 200 and status == "ok": count = resp.get("scanStatus", {}).get("count", 0) self._log.info("Updating Subsonic; scanning {} tracks", count) - elif ( - response.status_code == 200 - and status == "failed" - ): + elif response.status_code == 200 and status == "failed": msg = resp.get("error", {}).get("message", "Unknown error") - self._log.error( - "Error: {}", msg - ) + self._log.error("Error: {}", msg) else: self._log.error("Error: {}", json) except Exception as error: From 51be7be0b00876e2df8587b8142f5a1e6fc5c489 Mon Sep 17 00:00:00 2001 From: Jaslin Date: Fri, 5 Dec 2025 00:24:47 -0500 Subject: [PATCH 4/6] Simplifies subsonicupdate JSON handling and updated changelog --- beetsplug/subsonicupdate.py | 8 ++++---- docs/changelog.rst | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/beetsplug/subsonicupdate.py b/beetsplug/subsonicupdate.py index ace5546f4..8a4423782 100644 --- a/beetsplug/subsonicupdate.py +++ b/beetsplug/subsonicupdate.py @@ -138,6 +138,7 @@ class SubsonicUpdate(BeetsPlugin): params=payload, timeout=10, ) + response.raise_for_status() try: json = response.json() except ValueError: @@ -145,15 +146,14 @@ class SubsonicUpdate(BeetsPlugin): "Invalid JSON from Subsonic: {}", response.text[:200] ) return - resp = json.get("subsonic-response") - if not resp: + if not (resp := json.get("subsonic-response")): self._log.error("Missing 'subsonic-response' field: {}", json) return status = resp.get("status") - if response.status_code == 200 and status == "ok": + if status == "ok": count = resp.get("scanStatus", {}).get("count", 0) self._log.info("Updating Subsonic; scanning {} tracks", count) - elif response.status_code == 200 and status == "failed": + elif status == "failed": msg = resp.get("error", {}).get("message", "Unknown error") self._log.error("Error: {}", msg) else: diff --git a/docs/changelog.rst b/docs/changelog.rst index 82783ce0d..d3234e9a3 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -33,8 +33,8 @@ New features: resolve differences in metadata source styles. Bug fixes: -- :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 cryptic (e.g., "Expecting value: line 1 column 1 (char 0)"). :bug:`5635` - :doc:`plugins/inline`: Fix recursion error when an inline field definition shadows a built-in item field (e.g., redefining ``track_no``). Inline From 5f1975ceb20c802af6befe86191064a1a96b8c99 Mon Sep 17 00:00:00 2001 From: Jaslin Date: Fri, 5 Dec 2025 00:58:34 -0500 Subject: [PATCH 5/6] Simplify SubsonicUpdate JSON handling and fix changelog formatting --- docs/changelog.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index d3234e9a3..adc0b6474 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -33,9 +33,10 @@ New features: resolve differences in metadata source styles. Bug fixes: + - :doc:`plugins/subsonicupdate`: Improve error messages when the Subsonic server - is unavailable or returns invalid or missing JSON. Previously, failures were - cryptic (e.g., "Expecting value: line 1 column 1 (char 0)"). :bug:`5635` + is unavailable or returns invalid or missing JSON. Previously, failures were + cryptic (for instance, "Expecting value: line 1 column 1 (char 0)"). :bug:`5635` - :doc:`plugins/inline`: Fix recursion error when an inline field definition shadows a built-in item field (e.g., redefining ``track_no``). Inline expressions now skip self-references during evaluation to avoid infinite From 948cdaccb13f45396a95b028b3fe922634477974 Mon Sep 17 00:00:00 2001 From: Jaslin Date: Fri, 5 Dec 2025 03:20:11 -0500 Subject: [PATCH 6/6] Fix subsonicupdate entry in changelog --- docs/changelog.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index adc0b6474..e85b4413b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -35,8 +35,8 @@ New features: Bug fixes: - :doc:`plugins/subsonicupdate`: Improve error messages when the Subsonic server - is unavailable or returns invalid or missing JSON. Previously, failures were - cryptic (for instance, "Expecting value: line 1 column 1 (char 0)"). :bug:`5635` + is unavailable or returns invalid JSON. Previously, failures were cryptic + (for instance, "Expecting value: line 1 column 1 (char 0)"). :bug:`5635` - :doc:`plugins/inline`: Fix recursion error when an inline field definition shadows a built-in item field (e.g., redefining ``track_no``). Inline expressions now skip self-references during evaluation to avoid infinite