[clang] #101784 part 2: fix error handling of TranslationUnit.reparse (PR #102410)

via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 11 05:42:44 PDT 2024


================
@@ -161,7 +161,34 @@ class TranslationUnitLoadError(Exception):
     FIXME: Make libclang expose additional error information in this scenario.
     """
 
-    pass
+    # A generic error code, no further details are available.
+    #
+    # Errors of this kind can get their own specific error codes in future
+    # libclang versions.
+    ERROR_FAILURE = 1
+
+    # libclang crashed while performing the requested operation.
+    ERROR_CRASHED = 2
+
+    # The function detected that the arguments violate the function
+    # contract.
+    ERROR_INVALID_ARGUMENTS = 3
+
+    # An AST deserialization error has occurred.
+    ERROR_AST_READ_ERROR = 4
+
+    def __init__(self, enumeration: int, message: str):
+        assert isinstance(enumeration, int)
+
+        if enumeration < 1 or enumeration > 4:
+            raise Exception(
+                "Encountered undefined CXError "
+                "constant: %d. Please file a bug to have this "
+                "value supported." % enumeration
+            )
+
+        self.error_code = enumeration
+        Exception.__init__(self, "Error %d: %s" % (enumeration or 0, message))
----------------
TsXor wrote:

That is a leftover. Before the last commit, error code can be `None` because `create`/`parse` swallows error code. `%d` does not receive `None` so convert `None` to `0`.

https://github.com/llvm/llvm-project/pull/102410


More information about the cfe-commits mailing list