From: kaliko Date: Tue, 16 Nov 2021 10:23:42 +0000 (+0100) Subject: Revert previous refactoring around Exceptions X-Git-Tag: 0.18.0~7 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=3b4178f;p=mpd-sima.git Revert previous refactoring around Exceptions Mainly 774e755 and part of 94c7b5c PlayerError is musicpd.MPDError a different family of exceptions not to be merged in MPDSimaException, as initially implemented in a978d29. --- diff --git a/sima/launch.py b/sima/launch.py index 784d237..9c31397 100644 --- a/sima/launch.py +++ b/sima/launch.py @@ -36,6 +36,7 @@ from os import rename from . import core, info from .lib.logger import set_logger from .lib.simadb import SimaDB +from .mpdclient import PlayerError from .utils.config import ConfMan from .utils.startopt import StartOpt from .utils.utils import exception_log, SigHup, MPDSimaException @@ -183,7 +184,7 @@ def run(sopt, restart=False): start(sopt, restart) except SigHup: # SigHup inherit from Exception run(sopt, True) - except MPDSimaException as err: + except (MPDSimaException, PlayerError) as err: logger.error(err) sys.exit(2) except Exception: # Unhandled exception diff --git a/sima/mpdclient.py b/sima/mpdclient.py index c4ebade..6bbe63d 100644 --- a/sima/mpdclient.py +++ b/sima/mpdclient.py @@ -23,7 +23,7 @@ from logging import getLogger from select import select # external module -from musicpd import MPDClient, MPDError +from musicpd import MPDClient, MPDError as PlayerError # local import @@ -31,11 +31,6 @@ from .lib.meta import Meta, Artist, Album from .lib.track import Track from .lib.simastr import SimaStr from .utils.leven import levenshtein_ratio -from .utils.utils import MPDSimaException - - -class PlayerError(MPDSimaException): - """Fatal error in the player.""" # Some decorators @@ -130,8 +125,6 @@ class MPD(MPDClient): return super().__getattr__(cmd) except OSError as err: # socket errors raise PlayerError(err) from err - except MPDError as err: # hight level MPD client errors - raise PlayerError(err) from err def disconnect(self): """Overriding explicitly MPDClient.disconnect()""" @@ -161,7 +154,7 @@ class MPD(MPDClient): if password: try: self.password(password) - except (MPDError, OSError) as err: + except OSError as err: raise PlayerError(f"Could not connect to '{host}': {err}") from err # Controls we have sufficient rights available_cmd = self.commands() @@ -253,8 +246,6 @@ class MPD(MPDClient): self.noidle() 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 diff --git a/sima/utils/blcli.py b/sima/utils/blcli.py index a306b2c..4442abe 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, PlayerError, Artist, Album +from ..mpdclient import MPD, Artist, Album from ..lib.simadb import SimaDB @@ -35,11 +35,7 @@ class BLCli(MPD): cmd = options.get('command', None) if not cmd or not cmd.startswith('bl-'): return - try: - getattr(self, cmd.replace('-', '_'))() - except PlayerError as err: - self.log.error(err) - sys.exit(1) + getattr(self, cmd.replace('-', '_'))() def bl_view(self): blocklist = self.sdb.view_bl()