python-e3dc icon indicating copy to clipboard operation
python-e3dc copied to clipboard

Raise AuthenticationError if invalid RSCP key given

Open mdhom opened this issue 3 years ago • 1 comments

Tries to solve issue #17.

Before this PR, when a user passes a wrong RSCP key, an exception is thrown that is hard to understand and does not lead to understanding, that the RSCP key is wrong: struct.error: unpack requires a buffer of 2 bytes e3dc._e3dc_rscp_local.CommunicationError e3dc._e3dc.SendError: Max retries reached

With this PR, you now get a e3dc._e3dc.AuthenticationError which at least is a hint, that something with authentication went wrong.

For discussion: maybe add some exception message hinting to the RSCP key?

mdhom avatar Mar 06 '22 21:03 mdhom

I suggest creating a new exception for this:

class RSCPKeyError(Exception):
    """Class for RSCP Encryption Key Error Exception."""

    pass

and raise RSCPKeyError instead.

Being a specific error when using RSCP, this should be catched and reraised here: https://github.com/fsantini/python-e3dc/blob/master/e3dc/_e3dc.py#L504

except RSCPKeyError:
    raise

Lastly the RSCPKeyError should be exported in __init__.py.

vchrisb avatar Mar 08 '22 10:03 vchrisb