From 94c7b5c9c88a414afd30aa91b133afec6f3c4b6a Mon Sep 17 00:00:00 2001 From: kaliko Date: Fri, 29 Oct 2021 13:55:15 +0200 Subject: [PATCH] Fixed unhandled exception in monitor (idle MPD command) Socket timeout was handled but musicpd exception raised on server lost was not. For instance ConnectionError: "Connection lost while reading line" was not catch. --- sima/info.py | 2 +- sima/mpdclient.py | 30 ++++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/sima/info.py b/sima/info.py index 86ec802..799244b 100644 --- a/sima/info.py +++ b/sima/info.py @@ -12,7 +12,7 @@ short. """ -__version__ = '0.18.0.dev1' +__version__ = '0.18.0.dev2' __author__ = 'kaliko' __email__ = 'kaliko@azylum.org' __url__ = 'git://git.kaliko.me/sima.git' diff --git a/sima/mpdclient.py b/sima/mpdclient.py index 3bd13ae..c4ebade 100644 --- a/sima/mpdclient.py +++ b/sima/mpdclient.py @@ -238,21 +238,23 @@ class MPD(MPDClient): """ curr = self.current select_timeout = 5 - while True: - self.send_idle('database', 'playlist', 'player', 'options') - _read, _, _ = select([self], [], [], select_timeout) - if _read: # tries to read response - ret = self.fetch_idle() - if self._skipped_track(curr): - ret.append('skipped') - if 'database' in ret: - self._reset_cache() - return ret - # Nothing to read, canceling idle - try: # noidle cmd does not go through __getattr__, need to catch OSError then + try: # noidle cmd does not go through __getattr__, need to catch OSError then + while True: + self.send_idle('database', 'playlist', 'player', 'options') + _read, _, _ = select([self], [], [], select_timeout) + if _read: # tries to read response + ret = self.fetch_idle() + if self._skipped_track(curr): + ret.append('skipped') + if 'database' in ret: + self._reset_cache() + return ret + # Nothing to read, canceling idle self.noidle() - except OSError as err: - raise PlayerError(err) from err + except OSError as err: + raise PlayerError(err) from err + except MPDError as err: # hight level MPD client errors + raise PlayerError(err) from err def clean(self): """Clean blocking event (idle) and pending commands -- 2.39.2