Extract more RuleContext error-related methods into RuleErrorConsumer
This will make it easier to pass only error-handling functionality into support classes.
RELNOTES: None.
PiperOrigin-RevId: 172148072
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/LocationExpanderTest.java b/src/test/java/com/google/devtools/build/lib/analysis/LocationExpanderTest.java
index ae23f50..a60cd7c 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/LocationExpanderTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/LocationExpanderTest.java
@@ -16,6 +16,7 @@
import static com.google.common.truth.Truth.assertThat;
+import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
import com.google.devtools.build.lib.packages.RuleErrorConsumer;
import java.util.ArrayList;
import java.util.List;
@@ -48,6 +49,31 @@
public void attributeError(String attrName, String message) {
warnsOrErrors.add("ERROR-" + attrName + ": " + message);
}
+
+ @Override
+ public RuleErrorException throwWithRuleError(String message) throws RuleErrorException {
+ ruleError(message);
+ throw new RuleErrorException();
+ }
+
+ @Override
+ public RuleErrorException throwWithAttributeError(String attrName, String message)
+ throws RuleErrorException {
+ attributeError(attrName, message);
+ throw new RuleErrorException();
+ }
+
+ @Override
+ public boolean hasErrors() {
+ return !warnsOrErrors.isEmpty();
+ }
+
+ @Override
+ public void assertNoErrors() throws RuleErrorException {
+ if (hasErrors()) {
+ throw new RuleErrorException();
+ }
+ }
}
private LocationExpander makeExpander(RuleErrorConsumer ruleErrorConsumer) throws Exception {
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java b/src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java
index 27ca351..cd1992d 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java
@@ -24,6 +24,7 @@
import com.google.devtools.build.lib.actions.Root;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
+import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
import com.google.devtools.build.lib.packages.RuleErrorConsumer;
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.Path;
@@ -80,6 +81,31 @@
attributeErrorMessage = message;
}
+ @Override
+ public RuleErrorException throwWithRuleError(String message) throws RuleErrorException {
+ ruleError(message);
+ throw new RuleErrorException();
+ }
+
+ @Override
+ public RuleErrorException throwWithAttributeError(String attrName, String message)
+ throws RuleErrorException {
+ attributeError(attrName, message);
+ throw new RuleErrorException();
+ }
+
+ @Override
+ public boolean hasErrors() {
+ return ruleErrorMessage != null || attributeErrorMessage != null;
+ }
+
+ @Override
+ public void assertNoErrors() throws RuleErrorException {
+ if (hasErrors()) {
+ throw new RuleErrorException();
+ }
+ }
+
public Collection<String> getAndClearRuleWarnings() {
Collection<String> warnings = ImmutableList.copyOf(ruleWarnings);
ruleWarnings.clear();