[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.
GitOrigin-RevId: 8639e2aaaffe1c58fbab238b25d49620ca86a76d
diff --git a/examples/python/crashlog.py b/examples/python/crashlog.py
index 8869227..afae31f 100755
--- a/examples/python/crashlog.py
+++ b/examples/python/crashlog.py
@@ -383,6 +383,10 @@
pass
+class CrashLogParseException(Exception):
+ pass
+
+
class CrashLogParser:
def parse(self, debugger, path, verbose):
try:
@@ -409,12 +413,16 @@
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