Clean up RuleErrorException: stop allowing it to be called directly, require that it go through RuleErrorConsumer, and allow it to take a cause.
PiperOrigin-RevId: 296014466
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
index 1531c8a..301cc77 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
@@ -210,14 +210,22 @@
* messaging should be done via {@link RuleErrorConsumer}; this exception only interrupts
* configured target creation in cases where it can no longer continue.
*/
- public static final class RuleErrorException extends Exception {
- public RuleErrorException() {
+ final class RuleErrorException extends Exception {
+ RuleErrorException() {
super();
}
- public RuleErrorException(String message) {
+ RuleErrorException(String message) {
super(message);
}
+
+ RuleErrorException(Throwable cause) {
+ super(cause);
+ }
+
+ RuleErrorException(String message, Throwable cause) {
+ super(message, cause);
+ }
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleErrorConsumer.java b/src/main/java/com/google/devtools/build/lib/packages/RuleErrorConsumer.java
index 68dc985..9f033b5 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/RuleErrorConsumer.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/RuleErrorConsumer.java
@@ -48,16 +48,29 @@
void attributeError(String attrName, String message);
/**
- * Convenience function to report non-attribute-specific errors in the current rule and then
- * throw a {@link RuleErrorException}, immediately exiting the build invocation. Alternatively,
- * invoke {@link #ruleError} instead to collect additional error information before ending the
- * invocation.
+ * Convenience function to report non-attribute-specific errors in the current rule and then throw
+ * a {@link RuleErrorException}, immediately exiting the current rule, and shutting down the
+ * invocation in a no-keep-going build. If multiple errors are present, invoke {@link #ruleError}
+ * to collect additional error information before calling this method.
*/
default RuleErrorException throwWithRuleError(String message) throws RuleErrorException {
ruleError(message);
throw new RuleErrorException(message);
}
+ /** See {@link #throwWithRuleError(String)}. */
+ default RuleErrorException throwWithRuleError(Throwable cause) throws RuleErrorException {
+ ruleError(cause.getMessage());
+ throw new RuleErrorException(cause);
+ }
+
+ /** See {@link #throwWithRuleError(String)}. */
+ default RuleErrorException throwWithRuleError(String message, Throwable cause)
+ throws RuleErrorException {
+ ruleError(message);
+ throw new RuleErrorException(message, cause);
+ }
+
/**
* Convenience function to report attribute-specific errors in the current rule, and then throw a
* {@link RuleErrorException}, immediately exiting the build invocation. Alternatively, invoke