Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct exit code on invalid aquery --output #13660

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
import com.google.devtools.build.lib.runtime.CommandEnvironment;
import com.google.devtools.build.lib.runtime.QueryRuntimeHelper;
import com.google.devtools.build.lib.runtime.QueryRuntimeHelper.QueryRuntimeHelperException;
import com.google.devtools.build.lib.server.FailureDetails.ActionQuery;
import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
import com.google.devtools.build.lib.server.FailureDetails.Query;
import com.google.devtools.build.lib.server.FailureDetails.Query.Code;
import com.google.devtools.build.lib.skyframe.SkyframeExecutorWrappingWalkableGraph;
import com.google.devtools.build.lib.util.DetailedExitCode;
import com.google.devtools.build.lib.util.ExitCode;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.WalkableGraph;
import com.google.devtools.common.options.OptionsParsingException;
import java.io.IOException;
import java.util.Collection;
import java.util.Set;
Expand Down Expand Up @@ -68,7 +70,7 @@ protected void postProcessAnalysisResult(BuildRequest request, AnalysisResult an
.setMessage(
"Queries based on analysis results are not allowed if incrementality state"
+ " is not being kept")
.setQuery(Query.newBuilder().setCode(Code.ANALYSIS_QUERY_PREREQ_UNMET))
.setQuery(Query.newBuilder().setCode(Query.Code.ANALYSIS_QUERY_PREREQ_UNMET))
.build()));
}
try (QueryRuntimeHelper queryRuntimeHelper =
Expand All @@ -92,13 +94,18 @@ protected void postProcessAnalysisResult(BuildRequest request, AnalysisResult an
FailureDetail failureDetail =
FailureDetail.newBuilder()
.setMessage(errorMessage + ": " + e.getMessage())
.setQuery(Query.newBuilder().setCode(Code.OUTPUT_FORMATTER_IO_EXCEPTION))
.setQuery(Query.newBuilder().setCode(Query.Code.OUTPUT_FORMATTER_IO_EXCEPTION))
.build();
throw new ViewCreationFailedException(errorMessage, failureDetail, e);
}
env.getReporter().error(null, errorMessage, e);
} catch (QueryRuntimeHelperException e) {
throw new ExitException(DetailedExitCode.of(e.getFailureDetail()));
} catch (OptionsParsingException e) {
throw new ExitException(DetailedExitCode.of(ExitCode.COMMAND_LINE_ERROR, FailureDetail.newBuilder()
.setMessage(e.getMessage())
.setActionQuery(ActionQuery.newBuilder().setCode(ActionQuery.Code.INCORRECT_ARGUMENTS))
.build()));
}
}
}
Expand All @@ -118,7 +125,7 @@ private void doPostAnalysisQuery(
Collection<SkyKey> transitiveConfigurationKeys,
QueryRuntimeHelper queryRuntimeHelper,
QueryExpression queryExpression)
throws InterruptedException, QueryException, IOException, QueryRuntimeHelperException {
throws InterruptedException, QueryException, IOException, QueryRuntimeHelperException, OptionsParsingException {
WalkableGraph walkableGraph =
SkyframeExecutorWrappingWalkableGraph.of(env.getSkyframeExecutor());

Expand All @@ -143,14 +150,10 @@ private void doPostAnalysisQuery(
NamedThreadSafeOutputFormatterCallback<T> callback =
NamedThreadSafeOutputFormatterCallback.selectCallback(outputFormat, callbacks);
if (callback == null) {
env.getReporter()
.handle(
Event.error(
String.format(
"Invalid output format '%s'. Valid values are: %s",
outputFormat,
NamedThreadSafeOutputFormatterCallback.callbackNames(callbacks))));
return;
throw new OptionsParsingException(String.format(
"Invalid output format '%s'. Valid values are: %s",
outputFormat,
NamedThreadSafeOutputFormatterCallback.callbackNames(callbacks)));
}

// A certain subset of output formatters support "streaming" results - the formatter is called
Expand Down