Stop throwing an exception if a Package was successfully created but contains errors. Instead, require callers to process the package and throw if they need to.

This allows us to avoid embedding a Package in an exception, which is icky. This also allows us to remove Package#containsTemporaryErrors.

Most callers' changes are fairly straightforward. The exception is EnvironmentBackedRecursivePackageProvider, which cannot throw an exception of its own in case of a package with errors (because it doesn't do that in keep_going mode), but whose request for a package with errors *should* shut down the build in case of nokeep_going mode. To do this in Skyframe, we have a new PackageErrorFunction which is to be called only in this situation, and will unconditionally throw. EnvironmentBackedRecursivePackageProvider can then catch this exception and continue on as usual, except that the exception will shut down the thread pool in a nokeep_going build.

--
MOS_MIGRATED_REVID=103247761
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TransitiveBaseTraversalFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/TransitiveBaseTraversalFunction.java
index 5bb9c4f..130f681 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/TransitiveBaseTraversalFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/TransitiveBaseTraversalFunction.java
@@ -18,6 +18,7 @@
 import com.google.common.collect.Lists;
 import com.google.devtools.build.lib.events.Event;
 import com.google.devtools.build.lib.events.EventHandler;
+import com.google.devtools.build.lib.packages.BuildFileContainsErrorsException;
 import com.google.devtools.build.lib.packages.InputFile;
 import com.google.devtools.build.lib.packages.NoSuchPackageException;
 import com.google.devtools.build.lib.packages.NoSuchTargetException;
@@ -303,9 +304,13 @@
         return ValuesMissing.INSTANCE;
       }
 
+      Package pkg = packageValue.getPackage();
+      if (pkg.containsErrors()) {
+        throw new BuildFileContainsErrorsException(label.getPackageIdentifier());
+      }
       packageLoadedSuccessfully = true;
       try {
-        target = packageValue.getPackage().getTarget(label.getName());
+        target = pkg.getTarget(label.getName());
       } catch (NoSuchTargetException unexpected) {
         // Not expected since the TargetMarkerFunction would have failed earlier if the Target
         // was not present.
@@ -318,18 +323,9 @@
 
       // We know that a Target may be extracted, but we need to get it out of the Package
       // (which is known to be in error).
-      Package pkg;
-      try {
-        PackageValue packageValue = (PackageValue) env.getValueOrThrow(packageKey,
-            NoSuchPackageException.class);
-        if (packageValue == null) {
-          return ValuesMissing.INSTANCE;
-        }
-        throw new IllegalStateException(
-            "Expected bad package: " + label.getPackageIdentifier());
-      } catch (NoSuchPackageException nsp) {
-        pkg = Preconditions.checkNotNull(nsp.getPackage(), label.getPackageIdentifier());
-      }
+      PackageValue packageValue =
+          (PackageValue) Preconditions.checkNotNull(env.getValue(packageKey), label);
+      Package pkg = packageValue.getPackage();
       try {
         target = pkg.getTarget(label.getName());
       } catch (NoSuchTargetException nste) {