From: kaliko Date: Sun, 4 Jul 2021 17:26:15 +0000 (+0200) Subject: Cleanup Exceptions X-Git-Tag: 0.18.0~27 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=a978d29;p=mpd-sima.git Cleanup Exceptions --- diff --git a/sima/core.py b/sima/core.py index 695a18c..7f3631c 100644 --- a/sima/core.py +++ b/sima/core.py @@ -26,7 +26,7 @@ from collections import deque from logging import getLogger from .mpdclient import MPD as PlayerClient -from .mpdclient import PlayerError, MPDError +from .mpdclient import PlayerError from .lib.simadb import SimaDB from .lib.daemon import Daemon from .utils.utils import SigHup @@ -125,7 +125,7 @@ class Sima(Daemon): except PlayerError as err: self.log.debug(err) continue - except MPDError as err: + except PlayerError as err: #TODO: unhandled Player exceptions self.log.warning('Unhandled player exception: %s', err) self.log.info('Got reconnected') @@ -160,13 +160,13 @@ class Sima(Daemon): self.log.info('Connecting MPD: %(host)s:%(port)s', self.config['MPD']) self.player.connect() self.foreach_plugin('start') - except (PlayerError, MPDError) as err: + except PlayerError as err: self.log.warning('Player: %s', err) self.reconnect_player() while 42: try: self.loop() - except (PlayerError, MPDError) as err: + except PlayerError as err: self.log.warning('Player error: %s', err) self.reconnect_player() del self.changed diff --git a/sima/mpdclient.py b/sima/mpdclient.py index 45d3dcd..4e6af68 100644 --- a/sima/mpdclient.py +++ b/sima/mpdclient.py @@ -22,7 +22,7 @@ from functools import wraps from logging import getLogger # external module -from musicpd import MPDClient, MPDError +from musicpd import MPDClient, MPDError as PlayerError # local import @@ -32,10 +32,6 @@ from .lib.simastr import SimaStr from .utils.leven import levenshtein_ratio -class PlayerError(MPDError): - """Fatal error in the player.""" - - # Some decorators def bl_artist(func): def wrapper(*args, **kwargs): @@ -139,20 +135,20 @@ class MPD(MPDClient): try: super().connect(host, port) # Catch socket errors - except IOError as err: + except OSError as err: raise PlayerError('Could not connect to "%s:%s": %s' % (host, port, err.strerror)) # Catch all other possible errors # ConnectionError and ProtocolError are always fatal. Others may not # be, but we don't know how to handle them here, so treat them as if # they are instead of ignoring them. - except MPDError as err: + except PlayerError as err: raise PlayerError('Could not connect to "%s:%s": %s' % (host, port, err)) if password: try: self.password(password) - except (MPDError, IOError) as err: + except (PlayerError, OSError) as err: raise PlayerError("Could not connect to '%s': %s" % (host, err)) # Controls we have sufficient rights available_cmd = self.commands() @@ -232,7 +228,7 @@ class MPD(MPDClient): curr = self.current try: ret = self.idle('database', 'playlist', 'player', 'options') - except (MPDError, IOError) as err: + except (PlayerError, OSError) as err: raise PlayerError("Couldn't init idle: %s" % err) if self._skipped_track(curr): ret.append('skipped') diff --git a/sima/utils/blcli.py b/sima/utils/blcli.py index 63d3bf4..56f36ca 100644 --- a/sima/utils/blcli.py +++ b/sima/utils/blcli.py @@ -21,7 +21,7 @@ import atexit import sys # local import -from ..mpdclient import MPD, MPDError, Artist, Album +from ..mpdclient import MPD, PlayerError, Artist, Album from ..lib.simadb import SimaDB @@ -37,7 +37,7 @@ class BLCli(MPD): return try: getattr(self, cmd.replace('-', '_'))() - except MPDError as err: + except PlayerError as err: self.log.error(err) sys.exit(1) diff --git a/sima/utils/configtest.py b/sima/utils/configtest.py index b777276..ef91241 100644 --- a/sima/utils/configtest.py +++ b/sima/utils/configtest.py @@ -5,7 +5,7 @@ import sys from logging import getLogger from ..mpdclient import MPD -from ..mpdclient import MPDError, PlayerError +from ..mpdclient import PlayerError from ..plugins.internal.tags import forge_filter, control_config @@ -22,7 +22,7 @@ def tags_config_test(cli, config): try: # Use window to limit reponse size res = cli.find(filt, 'window', (0, 300)) - except MPDError as err: + except PlayerError as err: cli.disconnect() print('filter error: %s' % err, file=sys.stderr) sys.exit(1)