From 8639e2aaaffe1c58fbab238b25d49620ca86a76d Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Thu, 15 Apr 2021 15:15:20 -0700 Subject: [PATCH] [lldb] Raise a CrashLogParseException when failing to parse JSON crashlog Throw an exception with an actually helpful message when we fail to parse a JSON crashlog. --- lldb/examples/python/crashlog.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py index 8869227..afae31f 100755 --- a/lldb/examples/python/crashlog.py +++ b/lldb/examples/python/crashlog.py @@ -383,6 +383,10 @@ class CrashLogFormatException(Exception): pass +class CrashLogParseException(Exception): + pass + + class CrashLogParser: def parse(self, debugger, path, verbose): try: @@ -409,12 +413,16 @@ class JSONCrashLogParser: except ValueError: raise CrashLogFormatException() - self.parse_process_info(self.data) - self.parse_images(self.data['usedImages']) - self.parse_threads(self.data['threads']) - - thread = self.crashlog.threads[self.crashlog.crashed_thread_idx] - thread.reason = self.parse_crash_reason(self.data['exception']) + try: + self.parse_process_info(self.data) + self.parse_images(self.data['usedImages']) + self.parse_threads(self.data['threads']) + thread = self.crashlog.threads[self.crashlog.crashed_thread_idx] + thread.reason = self.parse_crash_reason(self.data['exception']) + except (KeyError, ValueError, TypeError) as e: + raise CrashLogParseException( + 'Failed to parse JSON crashlog: {}: {}'.format( + type(e).__name__, e)) return self.crashlog -- 2.7.4