except PlayerError as err:
self.log.debug(err)
continue
- except PlayerError as err:
- # TODO: unhandled Player exceptions
- self.log.warning('Unhandled player exception: %s', err)
self.log.info('Got reconnected')
break
self.foreach_plugin('start')
# -*- coding: utf-8 -*-
-# Copyright (c) 2014-2015, 2020 kaliko <kaliko@azylum.org>
+# Copyright (c) 2014-2015, 2020, 2021 kaliko <kaliko@azylum.org>
# Copyright (c) 2012, 2013 Eric Larson <eric@ionrock.org>
#
# This program is free software: you can redistribute it and/or modify
import email.utils
-from requests import Session, Request, Timeout, ConnectionError
+from requests import Session, Request, Timeout, ConnectionError as HTTPConnectionError
from sima import SOCKET_TIMEOUT, WAIT_BETWEEN_REQUESTS
from sima.utils.utils import WSError, WSTimeout, WSHTTPError, Throttle
return cached_response
try:
return self.fetch_ws(req)
- except Timeout:
+ except Timeout as err:
raise WSTimeout('Failed to reach server within {0}s'.format(
- SOCKET_TIMEOUT))
- except ConnectionError as err:
- raise WSError(err)
+ SOCKET_TIMEOUT)) from err
+ except HTTPConnectionError as err:
+ raise WSError(err) from err
@Throttle(WAIT_BETWEEN_REQUESTS)
def fetch_ws(self, prepreq):
import logging
import re
+from ..utils.utils import MPDSimaException
+
+
UUID_RE = r'^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[89AB][a-f0-9]{3}-[a-f0-9]{12}$'
#: The Track Object is collapsing multiple tags into a single string using this
# separator. It is used then to split back the string to tags list.
return False
-class MetaException(Exception):
+class MetaException(MPDSimaException):
"""Generic Meta Exception"""
from sima.lib.meta import Artist, Album
from sima.lib.track import Track
+from sima.utils.utils import MPDSimaException
-class SimaDBError(Exception):
+class SimaDBError(MPDSimaException):
"""
Exceptions.
"""
# -*- coding: utf-8 -*-
-# Copyright (c) 2009-2014 kaliko <kaliko@azylum.org>
+# Copyright (c) 2009-2014, 2021 kaliko <kaliko@azylum.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
ans = self.http(self.root_url, payload)
try:
ans.json()
- except ValueError:
+ except ValueError as err:
# Corrupted/malformed cache? cf. gitlab issue #35
- raise WSError('Malformed json, try purging the cache: %s')
+ raise WSError('Malformed json, try purging the cache: %s') from err
self._controls_answer(ans.json()) # pylint: disable=no-member
# Artist might be found but return no 'artist' list…
# cf. "Mulatu Astatqe" vs. "Mulatu Astatqé" with autocorrect=0
from select import select
# external module
-from musicpd import MPDClient, MPDError as PlayerError
+from musicpd import MPDClient, MPDError
# local import
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
return tracks_wrapper(super().__getattr__(cmd))
return super().__getattr__(cmd)
except OSError as err:
- raise PlayerError(err)
+ raise PlayerError(err) from err
def disconnect(self):
"""Overriding explicitly MPDClient.disconnect()"""
# Catch socket errors
except OSError as err:
raise PlayerError('Could not connect to "%s:%s": %s' %
- (host, port, err.strerror))
+ (host, port, err.strerror)) from err
# 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 PlayerError as err:
+ except MPDError as err:
raise PlayerError('Could not connect to "%s:%s": %s' %
- (host, port, err))
+ (host, port, err)) from err
if password:
try:
self.password(password)
- except (PlayerError, OSError) as err:
- raise PlayerError("Could not connect to '%s': %s" % (host, err))
+ except (MPDError, OSError) as err:
+ raise PlayerError("Could not connect to '%s': %s" % (host, err)) from err
# Controls we have sufficient rights
available_cmd = self.commands()
for cmd in MPD.needed_cmds:
if 'database' in ret:
self._reset_cache()
return ret
- else:
- try: # noidle cmd does not go through __getattr__, need to catch OSError then
- self.noidle()
- except OSError as err:
- raise PlayerError(err)
+ # Nothing to read, canceling idle
+ try: # noidle cmd does not go through __getattr__, need to catch OSError then
+ self.noidle()
+ except OSError as err:
+ raise PlayerError(err) from err
def clean(self):
"""Clean blocking event (idle) and pending commands
if self.plugin_conf['filter']:
# Use window to limit response size
self.player.find(self.plugin_conf['filter'], "window", (0, 1))
- except CommandError:
+ except CommandError as err:
raise PluginException('Badly formated filter in tags plugin configuration: "%s"'
- % self.plugin_conf['filter'])
+ % self.plugin_conf['filter']) from err
def callback_need_track(self):
candidates = []
if err.errno != errno.EEXIST:
raise
if (time.time() - start_time) >= self.timeout:
- raise FileLockException('Timeout occured.')
+ raise FileLockException('Timeout occured.') from err
time.sleep(self.delay)
self.is_locked = True
sys.exit(1)
-class SigHup(Exception):
- """SIGHUP raises this Exception"""
-
-
# ArgParse Callbacks
class Obsolete(Action):
# pylint: disable=R0903
"""Generic MPD_sima Exception"""
+class SigHup(MPDSimaException):
+ """SIGHUP raises this Exception"""
+
+
# http client exceptions (for webservices)
class WSError(MPDSimaException):
pass