From 04effa0ec1f644a8be65d5128c73abf8315b9405 Mon Sep 17 00:00:00 2001 From: coderkun Date: Sun, 18 Apr 2021 17:09:35 +0200 Subject: [PATCH] Fix error handling to operate on error number Fix the handling of MPD errors to compare the error number instead of the complete, unparsed error message. --- mcg/client.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mcg/client.py b/mcg/client.py index 7ef3028..166a18c 100644 --- a/mcg/client.py +++ b/mcg/client.py @@ -19,6 +19,7 @@ from mcg.utils import Utils class MPDException(Exception): def __init__(self, error): super(MPDException, self).__init__(self._parse_error(error)) + self._error = error def _parse_error(self, error): @@ -36,6 +37,10 @@ class MPDException(Exception): return self._error + def get_error_number(self): + return self._error_number + + def get_command_number(self): return self._command_number @@ -690,7 +695,7 @@ class Client(Base): break except CommandException as e: # If no albumart can be found, do not throw an exception - if e.get_error() == Client.PROTOCOL_ERROR_NOEXISTS: + if e.get_error_number() == Client.PROTOCOL_ERROR_NOEXISTS: data = None else: raise e @@ -773,7 +778,7 @@ class Client(Base): self._write(command, args) return self._read() except MPDException as e: - if command == 'idle' and e.get_error() == Client.PROTOCOL_ERROR_PERMISSION: + if command == 'idle' and e.get_error_number() == Client.PROTOCOL_ERROR_PERMISSION: self.disconnect() self._callback(Client.SIGNAL_ERROR, e) @@ -782,7 +787,7 @@ class Client(Base): try: self._write(command, args) except MPDException as e: - if command == 'idle' and e.get_error() == Client.PROTOCOL_ERROR_PERMISSION: + if command == 'idle' and e.get_error_number() == Client.PROTOCOL_ERROR_PERMISSION: self.disconnect() self._callback(Client.SIGNAL_ERROR, e)