28
28
import com .google .devtools .build .lib .runtime .CommandEnvironment ;
29
29
import com .google .devtools .build .lib .runtime .QueryRuntimeHelper ;
30
30
import com .google .devtools .build .lib .runtime .QueryRuntimeHelper .QueryRuntimeHelperException ;
31
+ import com .google .devtools .build .lib .server .FailureDetails .ActionQuery ;
31
32
import com .google .devtools .build .lib .server .FailureDetails .FailureDetail ;
32
33
import com .google .devtools .build .lib .server .FailureDetails .Query ;
33
- import com .google .devtools .build .lib .server .FailureDetails .Query .Code ;
34
34
import com .google .devtools .build .lib .skyframe .SkyframeExecutorWrappingWalkableGraph ;
35
35
import com .google .devtools .build .lib .util .DetailedExitCode ;
36
+ import com .google .devtools .build .lib .util .ExitCode ;
36
37
import com .google .devtools .build .skyframe .SkyKey ;
37
38
import com .google .devtools .build .skyframe .WalkableGraph ;
39
+ import com .google .devtools .common .options .OptionsParsingException ;
38
40
import java .io .IOException ;
39
41
import java .util .Collection ;
40
42
import java .util .Set ;
@@ -68,7 +70,7 @@ protected void postProcessAnalysisResult(BuildRequest request, AnalysisResult an
68
70
.setMessage (
69
71
"Queries based on analysis results are not allowed if incrementality state"
70
72
+ " 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 ))
72
74
.build ()));
73
75
}
74
76
try (QueryRuntimeHelper queryRuntimeHelper =
@@ -92,13 +94,22 @@ protected void postProcessAnalysisResult(BuildRequest request, AnalysisResult an
92
94
FailureDetail failureDetail =
93
95
FailureDetail .newBuilder ()
94
96
.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 ))
96
98
.build ();
97
99
throw new ViewCreationFailedException (errorMessage , failureDetail , e );
98
100
}
99
101
env .getReporter ().error (null , errorMessage , e );
100
102
} catch (QueryRuntimeHelperException e ) {
101
103
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 ()));
102
113
}
103
114
}
104
115
}
@@ -118,7 +129,8 @@ private void doPostAnalysisQuery(
118
129
Collection <SkyKey > transitiveConfigurationKeys ,
119
130
QueryRuntimeHelper queryRuntimeHelper ,
120
131
QueryExpression queryExpression )
121
- throws InterruptedException , QueryException , IOException , QueryRuntimeHelperException {
132
+ throws InterruptedException , QueryException , IOException , QueryRuntimeHelperException ,
133
+ OptionsParsingException {
122
134
WalkableGraph walkableGraph =
123
135
SkyframeExecutorWrappingWalkableGraph .of (env .getSkyframeExecutor ());
124
136
@@ -143,14 +155,10 @@ private void doPostAnalysisQuery(
143
155
NamedThreadSafeOutputFormatterCallback <T > callback =
144
156
NamedThreadSafeOutputFormatterCallback .selectCallback (outputFormat , callbacks );
145
157
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 )));
154
162
}
155
163
156
164
// A certain subset of output formatters support "streaming" results - the formatter is called
0 commit comments