From: kaliko Date: Fri, 29 Oct 2021 11:55:15 +0000 (+0200) Subject: Fixed unhandled exception in monitor (idle MPD command) X-Git-Tag: 0.18.0~11 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=94c7b5c;p=mpd-sima.git 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. --- 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