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 {