Make sure StepFailedException includes full description. Summary: I saw this while developing and decided the error message could have been more helpful. Test Plan: Sandcastle builds.
diff --git a/src/com/facebook/buck/step/StepFailedException.java b/src/com/facebook/buck/step/StepFailedException.java index 2a8785d..38bc94c 100644 --- a/src/com/facebook/buck/step/StepFailedException.java +++ b/src/com/facebook/buck/step/StepFailedException.java
@@ -37,12 +37,12 @@ Optional<BuildTarget> buildTarget) { String message; if (buildTarget.isPresent()) { - message = String.format("%s failed on step \"%s\" with exit code %d", + message = String.format("%s failed with exit code %d:\n%s", buildTarget.get().getFullyQualifiedName(), - step.getShortName(), - exitCode); + exitCode, + step.getDescription(context)); } else { - message = String.format("Failed with %d: %s", + message = String.format("Failed with exit code %d:\n%s", exitCode, step.getDescription(context)); }
diff --git a/test/com/facebook/buck/shell/GenruleFailingCommandIntegrationTest.java b/test/com/facebook/buck/shell/GenruleFailingCommandIntegrationTest.java index 50c05ef..8597813 100644 --- a/test/com/facebook/buck/shell/GenruleFailingCommandIntegrationTest.java +++ b/test/com/facebook/buck/shell/GenruleFailingCommandIntegrationTest.java
@@ -49,6 +49,7 @@ // We make sure that we failed for the right reason. assertThat(buildResult.getStderr(), - containsString("BUILD FAILED: //:fail failed on step \"genrule\" with exit code 1")); + containsString("BUILD FAILED: //:fail failed with exit code 1:\n" + + "/bin/bash -e -c 'false; echo >&2 hi'")); } }
diff --git a/test/com/facebook/buck/step/BUCK b/test/com/facebook/buck/step/BUCK index b5c2c4a..9366392 100644 --- a/test/com/facebook/buck/step/BUCK +++ b/test/com/facebook/buck/step/BUCK
@@ -31,6 +31,7 @@ '//lib:guava', '//lib:junit', '//src/com/facebook/buck/event:event', + '//src/com/facebook/buck/model:model', '//src/com/facebook/buck/step:step', '//src/com/facebook/buck/util:io', '//src/com/facebook/buck/util:util',
diff --git a/test/com/facebook/buck/step/StepFailedExceptionTest.java b/test/com/facebook/buck/step/StepFailedExceptionTest.java new file mode 100644 index 0000000..2bf542b --- /dev/null +++ b/test/com/facebook/buck/step/StepFailedExceptionTest.java
@@ -0,0 +1,54 @@ +/* + * Copyright 2013-present Facebook, Inc. + * + * 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.facebook.buck.step; + +import static org.junit.Assert.assertEquals; + +import com.facebook.buck.model.BuildTarget; +import com.google.common.base.Optional; + +import org.junit.Test; + +public class StepFailedExceptionTest { + + @Test + public void testCreateForFailingStepWithBuildTarget() { + final int exitCode = 17; + Step step = new FakeStep("cp", "cp foo bar", exitCode); + ExecutionContext context = TestExecutionContext.newInstance(); + BuildTarget buildTarget = new BuildTarget("//foo", "bar"); + StepFailedException exception = StepFailedException.createForFailingStep( + step, context, exitCode, Optional.of(buildTarget)); + + assertEquals(step, exception.getStep()); + assertEquals(exitCode, exception.getExitCode()); + assertEquals("//foo:bar failed with exit code 17:\ncp foo bar", exception.getMessage()); + } + + @Test + public void testCreateForFailingStepWithoutBuildTarget() { + final int exitCode = 17; + Step step = new FakeStep("cp", "cp foo bar", exitCode); + ExecutionContext context = TestExecutionContext.newInstance(); + StepFailedException exception = StepFailedException.createForFailingStep( + step, context, exitCode, Optional.<BuildTarget>absent()); + + assertEquals(step, exception.getStep()); + assertEquals(exitCode, exception.getExitCode()); + assertEquals("Failed with exit code 17:\ncp foo bar", exception.getMessage()); + } +}