From 36db5e965f1e8dba54b42e31082709b914dd5194 Mon Sep 17 00:00:00 2001 From: kaliko Date: Thu, 10 Feb 2022 17:17:49 +0100 Subject: [PATCH] Catch uncaught socket.timeout (OSError subclass). Wrap first call of MPD._reset_cache in try/catch, but I don't understand why... During first connection, player cache is populated with MPD._reset_cache Even though the connection to MPD succeed, we can receive a socket.timeout if the proxy is not reachable (MPD server in satellite mode request another MPD server for music library requests, for instance during _reset_cache). The issue here is the OSError (socket.timeout) is not raised as it should be, ie. wrapped in PlayerError within MPD.__getattr__. MPD._reset_cache is calling list('artist'), which is actually going through MPD.__getattr__, but when OSError is raised is is not wrapped in PlayerError. Launching mpd-sima against an MPD server on the same host but with a database proxy over the network can trigger this socket.timeout: * Start MPD * Shutdown internet link * Start mpd-sima --- sima/mpdclient.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sima/mpdclient.py b/sima/mpdclient.py index b50df91..cced48c 100644 --- a/sima/mpdclient.py +++ b/sima/mpdclient.py @@ -189,7 +189,13 @@ class MPD(MPDClient): self.log.warning('Use of MusicBrainzIdentifier disabled!') self.log.info('Consider using MusicBrainzIdentifier for your music library') self.use_mbid = Meta.use_mbid = False - self._reset_cache() + # TODO: Why do I need to intercept OSError here? + # why is it not wrapped in PlayerError in __getattr__? + # (cf. commit message for more) + try: + self._reset_cache() + except OSError as err: + raise PlayerError(f'Error during cache init: {err}') from err # ######### / Overriding MPDClient ######### def _reset_cache(self): -- 2.39.5