================ @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits