[Lldb-commits] [lldb] 8639e2a - [lldb] Raise a CrashLogParseException when failing to parse JSON crashlog

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 15 15:28:28 PDT 2021


Author: Jonas Devlieghere
Date: 2021-04-15T15:28:23-07:00
New Revision: 8639e2aaaffe1c58fbab238b25d49620ca86a76d

URL: https://github.com/llvm/llvm-project/commit/8639e2aaaffe1c58fbab238b25d49620ca86a76d
DIFF: https://github.com/llvm/llvm-project/commit/8639e2aaaffe1c58fbab238b25d49620ca86a76d.diff

LOG: [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.

Added: 
    

Modified: 
    lldb/examples/python/crashlog.py

Removed: 
    


################################################################################
diff  --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py
index 88692271bdcec..afae31f4a3620 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 @@ def parse(self):
         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
 


        


More information about the lldb-commits mailing list