host: raise a protocol error for empty messages

When decoding a message, first check that it is not empty and
raise a `ProtocolError` otherwise. This prevent a more obscure
error like "NoneType has no get method".
This commit is contained in:
Christian Kellner 2021-09-24 09:09:38 +00:00 committed by Tom Gundersen
parent 879c56a3b5
commit 6a39067772

View file

@ -78,6 +78,9 @@ class ServiceProtocol:
@staticmethod
def decode_message(msg: Dict) -> Tuple[str, Dict]:
if not msg:
raise ProtocolError("message empty")
t = msg.get("type")
if not t:
raise ProtocolError("'type' field missing")