msgproto: Catch exceptions during identify data parsing

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-07-04 12:40:42 -04:00
parent 0ac518040b
commit cf662b842b
1 changed files with 18 additions and 12 deletions

View File

@ -303,18 +303,24 @@ class MessageParser:
self.messages_by_id[msgid] = msg self.messages_by_id[msgid] = msg
self.messages_by_name[msg.name] = msg self.messages_by_name[msg.name] = msg
def process_identify(self, data, decompress=True): def process_identify(self, data, decompress=True):
if decompress: try:
data = zlib.decompress(data) if decompress:
self.raw_identify_data = data data = zlib.decompress(data)
data = json.loads(data) self.raw_identify_data = data
messages = data.get('messages') data = json.loads(data)
commands = data.get('commands') messages = data.get('messages')
responses = data.get('responses') commands = data.get('commands')
self._init_messages(messages, commands+responses) responses = data.get('responses')
static_strings = data.get('static_strings', {}) self._init_messages(messages, commands+responses)
self.static_strings = { int(k): v for k, v in static_strings.items() } static_strings = data.get('static_strings', {})
self.config.update(data.get('config', {})) self.static_strings = { int(k): v for k, v in static_strings.items() }
self.version = data.get('version', '') self.config.update(data.get('config', {}))
self.version = data.get('version', '')
except error as e:
raise
except Exception as e:
logging.exception("process_identify error")
raise error("Error during identify: %s" % (str(e),))
def get_constant(self, name): def get_constant(self, name):
try: try:
return self.config[name] return self.config[name]