2828import com .google .devtools .build .lib .runtime .CommandEnvironment ;
2929import com .google .devtools .build .lib .runtime .QueryRuntimeHelper ;
3030import com .google .devtools .build .lib .runtime .QueryRuntimeHelper .QueryRuntimeHelperException ;
31+ import com .google .devtools .build .lib .server .FailureDetails .ActionQuery ;
3132import com .google .devtools .build .lib .server .FailureDetails .FailureDetail ;
3233import com .google .devtools .build .lib .server .FailureDetails .Query ;
33- import com .google .devtools .build .lib .server .FailureDetails .Query .Code ;
3434import com .google .devtools .build .lib .skyframe .SkyframeExecutorWrappingWalkableGraph ;
3535import com .google .devtools .build .lib .util .DetailedExitCode ;
36+ import com .google .devtools .build .lib .util .ExitCode ;
3637import com .google .devtools .build .skyframe .SkyKey ;
3738import com .google .devtools .build .skyframe .WalkableGraph ;
39+ import com .google .devtools .common .options .OptionsParsingException ;
3840import java .io .IOException ;
3941import java .util .Collection ;
4042import java .util .Set ;
@@ -68,7 +70,7 @@ protected void postProcessAnalysisResult(BuildRequest request, AnalysisResult an
6870 .setMessage (
6971 "Queries based on analysis results are not allowed if incrementality state"
7072 + " is not being kept" )
71- .setQuery (Query .newBuilder ().setCode (Code .ANALYSIS_QUERY_PREREQ_UNMET ))
73+ .setQuery (Query .newBuilder ().setCode (Query . Code .ANALYSIS_QUERY_PREREQ_UNMET ))
7274 .build ()));
7375 }
7476 try (QueryRuntimeHelper queryRuntimeHelper =
@@ -92,13 +94,22 @@ protected void postProcessAnalysisResult(BuildRequest request, AnalysisResult an
9294 FailureDetail failureDetail =
9395 FailureDetail .newBuilder ()
9496 .setMessage (errorMessage + ": " + e .getMessage ())
95- .setQuery (Query .newBuilder ().setCode (Code .OUTPUT_FORMATTER_IO_EXCEPTION ))
97+ .setQuery (Query .newBuilder ().setCode (Query . Code .OUTPUT_FORMATTER_IO_EXCEPTION ))
9698 .build ();
9799 throw new ViewCreationFailedException (errorMessage , failureDetail , e );
98100 }
99101 env .getReporter ().error (null , errorMessage , e );
100102 } catch (QueryRuntimeHelperException e ) {
101103 throw new ExitException (DetailedExitCode .of (e .getFailureDetail ()));
104+ } catch (OptionsParsingException e ) {
105+ throw new ExitException (
106+ DetailedExitCode .of (
107+ ExitCode .COMMAND_LINE_ERROR ,
108+ FailureDetail .newBuilder ()
109+ .setMessage (e .getMessage ())
110+ .setActionQuery (
111+ ActionQuery .newBuilder ().setCode (ActionQuery .Code .INCORRECT_ARGUMENTS ))
112+ .build ()));
102113 }
103114 }
104115 }
@@ -118,7 +129,8 @@ private void doPostAnalysisQuery(
118129 Collection <SkyKey > transitiveConfigurationKeys ,
119130 QueryRuntimeHelper queryRuntimeHelper ,
120131 QueryExpression queryExpression )
121- throws InterruptedException , QueryException , IOException , QueryRuntimeHelperException {
132+ throws InterruptedException , QueryException , IOException , QueryRuntimeHelperException ,
133+ OptionsParsingException {
122134 WalkableGraph walkableGraph =
123135 SkyframeExecutorWrappingWalkableGraph .of (env .getSkyframeExecutor ());
124136
@@ -143,14 +155,10 @@ private void doPostAnalysisQuery(
143155 NamedThreadSafeOutputFormatterCallback <T > callback =
144156 NamedThreadSafeOutputFormatterCallback .selectCallback (outputFormat , callbacks );
145157 if (callback == null ) {
146- env .getReporter ()
147- .handle (
148- Event .error (
149- String .format (
150- "Invalid output format '%s'. Valid values are: %s" ,
151- outputFormat ,
152- NamedThreadSafeOutputFormatterCallback .callbackNames (callbacks ))));
153- return ;
158+ throw new OptionsParsingException (
159+ String .format (
160+ "Invalid output format '%s'. Valid values are: %s" ,
161+ outputFormat , NamedThreadSafeOutputFormatterCallback .callbackNames (callbacks )));
154162 }
155163
156164 // A certain subset of output formatters support "streaming" results - the formatter is called
0 commit comments