Skip to content

Commit

Permalink
Throw explicit exception if experimental_split_coverage_postprocessin…
Browse files Browse the repository at this point in the history
…g is used without experimental_fetch_all_coverage_outputs

This closes bazelbuild#13185
According to bazelbuild@a445cda,
The flag --experimental_split_coverage_postprocessing depends on the flag
--experimental_fetch_all_coverage_outputs being enabled, but if the former one
is set without the latter one, Bazel throws a quite confusing NullPointerException.
Now we throw an explicit exception with proper error message.
  • Loading branch information
blindpirate committed Aug 21, 2022
1 parent 5116e92 commit 01534ec
Showing 1 changed file with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,10 @@ public TestRunnerSpawn createTestRunnerSpawn(
throws ExecException, InterruptedException {
if (action.getExecutionSettings().getInputManifest() == null) {
String errorMessage = "cannot run local tests with --nobuild_runfile_manifests";
throw new TestExecException(
errorMessage,
FailureDetail.newBuilder()
.setTestAction(
TestAction.newBuilder().setCode(TestAction.Code.LOCAL_TEST_PREREQ_UNMET))
.setMessage(errorMessage)
.build());
throw createTestExecException(
TestAction.Code.LOCAL_TEST_PREREQ_UNMET,
"cannot run local tests with --nobuild_runfile_manifests"
);
}
Map<String, String> testEnvironment =
createEnvironment(
Expand Down Expand Up @@ -761,6 +758,16 @@ public void finalizeCancelledTest(List<FailedAttemptResult> failedAttempts) thro
}
}

private static TestExecException createTestExecException(TestAction.Code errorCode, String errorMessage) {
return new TestExecException(
errorMessage,
FailureDetail.newBuilder()
.setTestAction(TestAction.newBuilder().setCode(errorCode))
.setMessage(errorMessage)
.build()
);
}

private final class BazelTestAttemptContinuation extends TestAttemptContinuation {
private final TestRunnerAction testAction;
@Nullable private final TestMetadataHandler testMetadataHandler;
Expand Down Expand Up @@ -884,6 +891,13 @@ public TestAttemptContinuation execute()
.setHasCoverage(testAction.isCoverageMode());

if (testAction.isCoverageMode() && testAction.getSplitCoveragePostProcessing()) {
if (testAction.getCoverageDirectoryTreeArtifact() == null) {
// Otherwise we'll get a NPE https://github.com/bazelbuild/bazel/issues/13185
throw createTestExecException(
TestAction.Code.LOCAL_TEST_PREREQ_UNMET,
"coverageDirectoryTreeArtifact is null: --experimental_split_coverage_postprocessing depends on --experimental_fetch_all_coverage_outputs being enabled"
);
}
actionExecutionContext
.getMetadataHandler()
.getMetadata(testAction.getCoverageDirectoryTreeArtifact());
Expand Down

0 comments on commit 01534ec

Please sign in to comment.