[clang] #101784 part 2: fix error handling of TranslationUnit.reparse (PR #102410)
Jannick Kremer via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 11 01:59:10 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))
----------------
DeinAlptraum wrote:
What do you need the `or 0` for?
https://github.com/llvm/llvm-project/pull/102410
More information about the cfe-commits
mailing list