aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java
index 234c03a490..520d08cb45 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java
@@ -165,10 +165,13 @@ public final class QueryCommand implements BlazeCommand {
} else {
callback = new AggregateAllOutputFormatterCallback<>();
}
+ boolean catastrophe = true;
try {
callback.start();
result = queryEnv.evaluateQuery(expr, callback);
+ catastrophe = false;
} catch (QueryException e) {
+ catastrophe = false;
// Keep consistent with reportBuildFileError()
env.getReporter()
// TODO(bazel-team): this is a kludge to fix a bug observed in the wild. We should make
@@ -176,6 +179,7 @@ public final class QueryCommand implements BlazeCommand {
.handle(Event.error(e.getMessage() == null ? e.toString() : e.getMessage()));
return ExitCode.ANALYSIS_FAILURE;
} catch (InterruptedException e) {
+ catastrophe = false;
IOException ioException = callback.getIoException();
if (ioException == null || ioException instanceof ClosedByInterruptException) {
env.getReporter().handle(Event.error("query interrupted"));
@@ -185,17 +189,20 @@ public final class QueryCommand implements BlazeCommand {
return ExitCode.LOCAL_ENVIRONMENTAL_ERROR;
}
} catch (IOException e) {
+ catastrophe = false;
env.getReporter().handle(Event.error("I/O error: " + e.getMessage()));
return ExitCode.LOCAL_ENVIRONMENTAL_ERROR;
} finally {
- if (streamResults) {
- output.flush();
- }
- try {
- callback.close();
- } catch (IOException e) {
- env.getReporter().handle(Event.error("I/O error: " + e.getMessage()));
- return ExitCode.LOCAL_ENVIRONMENTAL_ERROR;
+ if (!catastrophe) {
+ if (streamResults) {
+ output.flush();
+ }
+ try {
+ callback.close();
+ } catch (IOException e) {
+ env.getReporter().handle(Event.error("I/O error: " + e.getMessage()));
+ return ExitCode.LOCAL_ENVIRONMENTAL_ERROR;
+ }
}
}