Skip to content

Commit f95b80d

Browse files
fmeumcopybara-github
authored andcommitted
Include cause when reporting ActionExecutionException
`SkyframeActionExecutor#toActionExecutionException` claimed to combine the user-provided message and the exception's message when reporting an error, but did not. This is fixed so that errors can be diagnosed directly from the build logs, without having to look into `java.log`. Work towards bazelbuild#10363 Closes bazelbuild#18169. PiperOrigin-RevId: 526195991 Change-Id: I978a6d739c37384121acccccf95e8dcb80ac5d25
1 parent 166ef61 commit f95b80d

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

src/main/java/com/google/devtools/build/lib/actions/ActionExecutionException.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public ActionExecutionException(
5757
ActionAnalysisMetadata action,
5858
boolean catastrophe,
5959
DetailedExitCode detailedExitCode) {
60-
super(message, cause);
60+
super(combineMessages(message, cause), cause);
6161
this.action = action;
6262
this.catastrophe = catastrophe;
6363
this.detailedExitCode = checkNotNull(detailedExitCode);
@@ -96,7 +96,7 @@ public ActionExecutionException(
9696
NestedSet<Cause> rootCauses,
9797
boolean catastrophe,
9898
DetailedExitCode detailedExitCode) {
99-
super(message, cause);
99+
super(combineMessages(message, cause), cause);
100100
this.action = action;
101101
this.rootCauses = rootCauses;
102102
this.catastrophe = catastrophe;
@@ -203,4 +203,12 @@ public DetailedExitCode getDetailedExitCode() {
203203
public boolean showError() {
204204
return getMessage() != null;
205205
}
206+
207+
@Nullable
208+
private static String combineMessages(String message, @Nullable Throwable cause) {
209+
if (cause == null || cause.getMessage() == null) {
210+
return message;
211+
}
212+
return message + ": " + cause.getMessage();
213+
}
206214
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2018 The Bazel Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.devtools.build.lib.actions;
16+
17+
import static com.google.common.truth.Truth.assertThat;
18+
19+
import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
20+
import com.google.devtools.build.lib.actions.util.TestAction.DummyAction;
21+
import com.google.devtools.build.lib.server.FailureDetails.Execution;
22+
import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
23+
import com.google.devtools.build.lib.util.DetailedExitCode;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
import org.junit.runners.JUnit4;
27+
28+
/** {@link ActionExecutionException}Test */
29+
@RunWith(JUnit4.class)
30+
public final class ActionExecutionExceptionTest {
31+
32+
@Test
33+
public void containsCauseMessage() {
34+
Exception e =
35+
new ActionExecutionException(
36+
"message",
37+
new Exception("cause"),
38+
new DummyAction(ActionsTestUtil.DUMMY_ARTIFACT, ActionsTestUtil.DUMMY_ARTIFACT),
39+
false,
40+
DetailedExitCode.of(
41+
FailureDetail.newBuilder().setExecution(Execution.getDefaultInstance()).build()));
42+
assertThat(e).hasMessageThat().contains("message");
43+
assertThat(e).hasMessageThat().contains("cause");
44+
}
45+
}

src/test/java/com/google/devtools/build/lib/actions/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ java_library(
6464
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils",
6565
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils:depsutils",
6666
"//src/main/java/com/google/devtools/build/lib/util",
67+
"//src/main/java/com/google/devtools/build/lib/util:detailed_exit_code",
6768
"//src/main/java/com/google/devtools/build/lib/util:filetype",
6869
"//src/main/java/com/google/devtools/build/lib/util:string",
6970
"//src/main/java/com/google/devtools/build/lib/vfs",

0 commit comments

Comments
 (0)