1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-13 21:52:18 +00:00

Fix exception handling

Bare excepts will catch `GeneratorExit` exceptions which are raised
whenever a generator stops. This was causing issues when transcoding and
caching the results.

All instances of bare excepts have been replaced with scoped versions.
This commit is contained in:
Carey Metcalfe 2020-11-13 14:33:36 -05:00
parent d6c00e0f3d
commit bc6e768627
6 changed files with 10 additions and 8 deletions

View File

@ -41,7 +41,7 @@ def decode_password(password):
try: try:
return binascii.unhexlify(password[4:].encode("utf-8")).decode("utf-8") return binascii.unhexlify(password[4:].encode("utf-8")).decode("utf-8")
except: except ValueError:
return password return password

View File

@ -164,7 +164,8 @@ def stream_media():
if not data: if not data:
break break
yield data yield data
except: # pragma: nocover except BaseException:
# Make sure child processes are always killed
if dec_proc != None: if dec_proc != None:
dec_proc.kill() dec_proc.kill()
proc.kill() proc.kill()

View File

@ -159,9 +159,10 @@ class Cache(object):
self._make_space(size, key=key) self._make_space(size, key=key)
os.replace(f.name, self._filepath(key)) os.replace(f.name, self._filepath(key))
self._record_file(key, size) self._record_file(key, size)
except: except Exception:
f.close() f.close()
os.remove(f.name) with contextlib.suppress(OSError):
os.remove(f.name)
raise raise
def set(self, key, value): def set(self, key, value):

View File

@ -157,6 +157,6 @@ class Jukebox(object):
logger.debug("Start playing with command %s", args) logger.debug("Start playing with command %s", args)
try: try:
return Popen(args, stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL) return Popen(args, stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL)
except: except Exception:
logger.exception("Failed running play command") logger.exception("Failed to run play command")
return None return None

View File

@ -5,7 +5,7 @@ import uuid
try: try:
bytes = buffer bytes = buffer
except: except NameError:
pass pass
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()

View File

@ -5,7 +5,7 @@ import uuid
try: try:
bytes = buffer bytes = buffer
except: except NameError:
pass pass
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()