[lldb] Raise a CrashLogParseException when failing to parse JSON crashlog
authorJonas Devlieghere <jonas@devlieghere.com>
Thu, 15 Apr 2021 22:15:20 +0000 (15:15 -0700)
committerJonas Devlieghere <jonas@devlieghere.com>
Thu, 15 Apr 2021 22:28:23 +0000 (15:28 -0700)
Throw an exception with an actually helpful message when we fail to
parse a JSON crashlog.

lldb/examples/python/crashlog.py

index 8869227..afae31f 100755 (executable)
@@ -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