Add new FailureDetail Category "ActionCache".
Add ActionCache initialization failure code to ActionCache FailureDetails and used it for ExecutionTool.
RELNOTES: None.
PiperOrigin-RevId: 310549570
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java
index a41c8a8..08cff24 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java
@@ -81,11 +81,15 @@
import com.google.devtools.build.lib.runtime.BlazeModule;
import com.google.devtools.build.lib.runtime.BlazeRuntime;
import com.google.devtools.build.lib.runtime.CommandEnvironment;
+import com.google.devtools.build.lib.server.FailureDetails;
+import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
import com.google.devtools.build.lib.skyframe.AspectValueKey.AspectKey;
import com.google.devtools.build.lib.skyframe.Builder;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetKey;
import com.google.devtools.build.lib.skyframe.SkyframeExecutor;
import com.google.devtools.build.lib.util.AbruptExitException;
+import com.google.devtools.build.lib.util.DetailedExitCode;
+import com.google.devtools.build.lib.util.ExitCode;
import com.google.devtools.build.lib.util.LoggingUtil;
import com.google.devtools.build.lib.vfs.ModifiedFileSet;
import com.google.devtools.build.lib.vfs.OutputService;
@@ -693,7 +697,7 @@
}
/** Get action cache if present or reload it from the on-disk cache. */
- private ActionCache getActionCache() throws LocalEnvironmentException {
+ private ActionCache getActionCache() throws AbruptExitException {
try {
return env.getPersistentActionCache();
} catch (IOException e) {
@@ -701,10 +705,21 @@
// caches.
LoggingUtil.logToRemote(
Level.WARNING, "Failed to initialize action cache: " + e.getMessage(), e);
- throw new LocalEnvironmentException(
- "couldn't create action cache: "
- + e.getMessage()
- + ". If error persists, use 'bazel clean'");
+ String message =
+ String.format(
+ "Couldn't create action cache: %s. If error persists, use 'bazel clean'.",
+ e.getMessage());
+ FailureDetails.ActionCache failureDetailsActionCache =
+ FailureDetails.ActionCache.newBuilder()
+ .setCode(FailureDetails.ActionCache.Code.INITIALIZATION_FAILURE)
+ .build();
+ throw detailedAbruptExitException(
+ ExitCode.LOCAL_ENVIRONMENTAL_ERROR,
+ FailureDetail.newBuilder()
+ .setMessage(message)
+ .setActionCache(failureDetailsActionCache)
+ .build(),
+ e);
}
}
@@ -788,6 +803,11 @@
env.getEventBus().post(builder.build());
}
+ private static AbruptExitException detailedAbruptExitException(
+ ExitCode exitCode, FailureDetail failureDetail, Throwable e) {
+ return new AbruptExitException(DetailedExitCode.of(exitCode, failureDetail), e);
+ }
+
private Reporter getReporter() {
return env.getReporter();
}
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/LocalEnvironmentException.java b/src/main/java/com/google/devtools/build/lib/buildtool/LocalEnvironmentException.java
deleted file mode 100644
index b310ea9..0000000
--- a/src/main/java/com/google/devtools/build/lib/buildtool/LocalEnvironmentException.java
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2014 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.lib.buildtool;
-
-import com.google.devtools.build.lib.util.AbruptExitException;
-import com.google.devtools.build.lib.util.ExitCode;
-
-/**
- * An exception that signals that something is wrong with the user's environment
- * that they can fix. Used to report the problem of having no free space left in
- * the blaze output directory.
- *
- * <p>Note that this is a much higher level exception then the similarly named
- * EnvironmentExecException, which is thrown from the base Client and Strategy
- * layers of Blaze.
- *
- * <p>This exception is only thrown when we've decided that the build has, in
- * fact, failed and we should exit.
- */
-public class LocalEnvironmentException extends AbruptExitException {
-
- public LocalEnvironmentException(String message) {
- super(message, ExitCode.LOCAL_ENVIRONMENTAL_ERROR);
- }
-
- public LocalEnvironmentException(Throwable cause) {
- super(ExitCode.LOCAL_ENVIRONMENTAL_ERROR, cause);
- }
-
- public LocalEnvironmentException(String message, Throwable cause) {
- super(message, ExitCode.LOCAL_ENVIRONMENTAL_ERROR, cause);
- }
-}
diff --git a/src/main/protobuf/failure_details.proto b/src/main/protobuf/failure_details.proto
index c633ed0..ee2e12a 100644
--- a/src/main/protobuf/failure_details.proto
+++ b/src/main/protobuf/failure_details.proto
@@ -110,6 +110,7 @@
MemoryOptions memory_options = 129;
Query query = 130;
LocalExecution local_execution = 132;
+ ActionCache action_cache = 134;
}
reserved 102; // For internal use
@@ -484,3 +485,12 @@
Code code = 1;
}
+
+message ActionCache {
+ enum Code {
+ ACTION_CACHE_UNKNOWN = 0 [(metadata) = { exit_code: 37 }];
+ INITIALIZATION_FAILURE = 1 [(metadata) = { exit_code: 36 }];
+ }
+
+ Code code = 1;
+}