Recover from protobuf errors

This commit is contained in:
Otto Winter 2019-01-19 15:25:48 +01:00
parent 16fb2bff90
commit 19118f9f3c
No known key found for this signature in database
GPG Key ID: DB66C0BE6013F97E
1 changed files with 4 additions and 1 deletions

View File

@ -530,7 +530,10 @@ class APIConnection:
return
msg = MESSAGE_TYPE_TO_PROTO[msg_type]()
msg.ParseFromString(raw_msg)
try:
msg.ParseFromString(raw_msg)
except Exception as e:
raise APIConnectionError("Invalid protobuf message: {}".format(e))
_LOGGER.debug("%s: Got message of type %s: %s", self._params.address, type(msg), msg)
for msg_handler in self._message_handlers[:]:
msg_handler(msg)