Fix: Handle retry exception during authentication in Bluesound provider (#1778)
authorBrian O'Connor <btoconnor@users.noreply.github.com>
Sat, 16 Nov 2024 15:24:29 +0000 (10:24 -0500)
committerGitHub <noreply@github.com>
Sat, 16 Nov 2024 15:24:29 +0000 (16:24 +0100)
music_assistant/providers/siriusxm/__init__.py

index e971c30ce74a60c453319f4d2cdb0beed8a5e8dc..339e8622907893a696a2e502a1bd6ada2de8d49a 100644 (file)
@@ -26,6 +26,7 @@ from music_assistant_models.media_items import (
     Radio,
 )
 from music_assistant_models.streamdetails import StreamDetails
+from tenacity import RetryError
 
 from music_assistant.helpers.util import select_free_port
 from music_assistant.helpers.webserver import Webserver
@@ -136,7 +137,18 @@ class SiriusXMProvider(MusicProvider):
         )
 
         self.logger.info("Authenticating with SiriusXM")
-        if not await self._client.authenticate():
+        try:
+            if not await self._client.authenticate():
+                raise LoginFailed("Could not login to SiriusXM")
+        except RetryError:
+            # It looks like there's a bug in the sxm-client code
+            # where it won't return False if there's bad credentials.
+            # Due to the retry logic, it's attempting to log in multiple
+            # times and then finally raises an unrelated exception,
+            # rather than returning False or raising the package's
+            # AuthenticationError.
+            # Therefore, we're resorting to catching the RetryError
+            # here and recognizing it as a login failure.
             raise LoginFailed("Could not login to SiriusXM")
 
         self.logger.info("Successfully authenticated")