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_name[msg.name] = msg
def process_identify(self, data, decompress=True):
if decompress:
data = zlib.decompress(data)
self.raw_identify_data = data
data = json.loads(data)
messages = data.get('messages')
commands = data.get('commands')
responses = data.get('responses')
self._init_messages(messages, commands+responses)
static_strings = data.get('static_strings', {})
self.static_strings = { int(k): v for k, v in static_strings.items() }
self.config.update(data.get('config', {}))
self.version = data.get('version', '')
try:
if decompress:
data = zlib.decompress(data)
self.raw_identify_data = data
data = json.loads(data)
messages = data.get('messages')
commands = data.get('commands')
responses = data.get('responses')
self._init_messages(messages, commands+responses)
static_strings = data.get('static_strings', {})
self.static_strings = { int(k): v for k, v in static_strings.items() }
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):
try:
return self.config[name]