Skip to content

Commit

Permalink
Include cause when reporting ActionExecutionException
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
fmeum authored and copybara-github committed Apr 22, 2023
1 parent 166ef61 commit f95b80d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ActionExecutionException(
ActionAnalysisMetadata action,
boolean catastrophe,
DetailedExitCode detailedExitCode) {
super(message, cause);
super(combineMessages(message, cause), cause);
this.action = action;
this.catastrophe = catastrophe;
this.detailedExitCode = checkNotNull(detailedExitCode);
Expand Down Expand Up @@ -96,7 +96,7 @@ public ActionExecutionException(
NestedSet<Cause> rootCauses,
boolean catastrophe,
DetailedExitCode detailedExitCode) {
super(message, cause);
super(combineMessages(message, cause), cause);
this.action = action;
this.rootCauses = rootCauses;
this.catastrophe = catastrophe;
Expand Down Expand Up @@ -203,4 +203,12 @@ public DetailedExitCode getDetailedExitCode() {
public boolean showError() {
return getMessage() != null;
}

@Nullable
private static String combineMessages(String message, @Nullable Throwable cause) {
if (cause == null || cause.getMessage() == null) {
return message;
}
return message + ": " + cause.getMessage();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2018 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.actions;

import static com.google.common.truth.Truth.assertThat;

import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
import com.google.devtools.build.lib.actions.util.TestAction.DummyAction;
import com.google.devtools.build.lib.server.FailureDetails.Execution;
import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
import com.google.devtools.build.lib.util.DetailedExitCode;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** {@link ActionExecutionException}Test */
@RunWith(JUnit4.class)
public final class ActionExecutionExceptionTest {

@Test
public void containsCauseMessage() {
Exception e =
new ActionExecutionException(
"message",
new Exception("cause"),
new DummyAction(ActionsTestUtil.DUMMY_ARTIFACT, ActionsTestUtil.DUMMY_ARTIFACT),
false,
DetailedExitCode.of(
FailureDetail.newBuilder().setExecution(Execution.getDefaultInstance()).build()));
assertThat(e).hasMessageThat().contains("message");
assertThat(e).hasMessageThat().contains("cause");
}
}
1 change: 1 addition & 0 deletions src/test/java/com/google/devtools/build/lib/actions/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils:depsutils",
"//src/main/java/com/google/devtools/build/lib/util",
"//src/main/java/com/google/devtools/build/lib/util:detailed_exit_code",
"//src/main/java/com/google/devtools/build/lib/util:filetype",
"//src/main/java/com/google/devtools/build/lib/util:string",
"//src/main/java/com/google/devtools/build/lib/vfs",
Expand Down

0 comments on commit f95b80d

Please sign in to comment.