Throw InterruptedException directly if a query is interrupted, instead of wrapping it in a QueryException.
QueryException should usually indicate a persistent failure, while an InterruptedException is transient. Wrapping the InterruptedException in a QueryException just obfuscates state.
--
MOS_MIGRATED_REVID=97815388
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java b/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java
index 42280e3..a9dccef 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java
@@ -119,7 +119,7 @@
// 2. Evaluate expression:
try {
env.evaluateQuery(expr);
- } catch (QueryException e) {
+ } catch (QueryException | InterruptedException e) {
// Keep consistent with reportBuildFileError()
runtime.getReporter().handle(Event.error(e.getMessage()));
return ExitCode.COMMAND_LINE_ERROR;
diff --git a/src/main/java/com/google/devtools/build/lib/query2/AbstractBlazeQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/AbstractBlazeQueryEnvironment.java
index 95a86ef..27b0838 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/AbstractBlazeQueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/AbstractBlazeQueryEnvironment.java
@@ -131,7 +131,8 @@
* @throws QueryException if the evaluation failed and {@code --nokeep_going} was in
* effect
*/
- public QueryEvalResult<T> evaluateQuery(QueryExpression expr) throws QueryException {
+ public QueryEvalResult<T> evaluateQuery(QueryExpression expr)
+ throws QueryException, InterruptedException {
resolvedTargetPatterns.clear();
// In the --nokeep_going case, errors are reported in the order in which the patterns are
@@ -167,7 +168,8 @@
return new QueryEvalResult<>(!eventHandler.hasErrors(), resultNodes);
}
- public QueryEvalResult<T> evaluateQuery(String query) throws QueryException {
+ public QueryEvalResult<T> evaluateQuery(String query)
+ throws QueryException, InterruptedException {
return evaluateQuery(QueryExpression.parse(query, this));
}
diff --git a/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java
index a5c6d1d..db9d637 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java
@@ -95,7 +95,8 @@
}
@Override
- public BlazeQueryEvalResult<Target> evaluateQuery(QueryExpression expr) throws QueryException {
+ public BlazeQueryEvalResult<Target> evaluateQuery(QueryExpression expr)
+ throws QueryException, InterruptedException {
// Some errors are reported as QueryExceptions and others as ERROR events (if --keep_going). The
// result is set to have an error iff there were errors emitted during the query, so we reset
// errors here.
@@ -241,16 +242,11 @@
@Override
public void buildTransitiveClosure(QueryExpression caller,
Set<Target> targetNodes,
- int maxDepth) throws QueryException {
+ int maxDepth) throws QueryException, InterruptedException {
Set<Target> targets = targetNodes;
preloadTransitiveClosure(targets, maxDepth);
-
- try {
- labelVisitor.syncWithVisitor(eventHandler, targets, keepGoing,
- loadingPhaseThreads, maxDepth, errorObserver, new GraphBuildingObserver());
- } catch (InterruptedException e) {
- throw new QueryException(caller, "transitive closure computation was interrupted");
- }
+ labelVisitor.syncWithVisitor(eventHandler, targets, keepGoing,
+ loadingPhaseThreads, maxDepth, errorObserver, new GraphBuildingObserver());
if (errorObserver.hasErrors()) {
reportBuildFileError(caller, "errors were encountered while computing transitive closure");
diff --git a/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
index d98b933..cb0f2f6 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
@@ -138,16 +138,12 @@
@Override
public QueryEvalResult<Target> evaluateQuery(QueryExpression expr)
- throws QueryException {
+ throws QueryException, InterruptedException {
// Some errors are reported as QueryExceptions and others as ERROR events (if --keep_going). The
// result is set to have an error iff there were errors emitted during the query, so we reset
// errors here.
eventHandler.resetErrors();
- try {
- init();
- } catch (InterruptedException e) {
- throw new QueryException(e.getMessage());
- }
+ init();
return super.evaluateQuery(expr);
}
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/AllPathsFunction.java b/src/main/java/com/google/devtools/build/lib/query2/engine/AllPathsFunction.java
index 4920298..ca307a8 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/AllPathsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/AllPathsFunction.java
@@ -49,7 +49,7 @@
@Override
public <T> Set<T> eval(QueryEnvironment<T> env, QueryExpression expression, List<Argument> args)
- throws QueryException {
+ throws QueryException, InterruptedException {
QueryExpression from = args.get(0).getExpression();
QueryExpression to = args.get(1).getExpression();
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/AllRdepsFunction.java b/src/main/java/com/google/devtools/build/lib/query2/engine/AllRdepsFunction.java
index 5f1493e..ac23525 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/AllRdepsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/AllRdepsFunction.java
@@ -59,7 +59,7 @@
* predicate.
*/
protected <T> Set<T> eval(QueryEnvironment<T> env, List<Argument> args, Predicate<T> universe)
- throws QueryException {
+ throws QueryException, InterruptedException {
Set<T> argumentValue = args.get(0).getExpression().eval(env);
int depthBound = args.size() > 1 ? args.get(1).getInteger() : Integer.MAX_VALUE;
Set<T> visited = new LinkedHashSet<>();
@@ -90,7 +90,7 @@
/** Breadth-first search from the argument. */
@Override
public <T> Set<T> eval(QueryEnvironment<T> env, QueryExpression expression, List<Argument> args)
- throws QueryException {
+ throws QueryException, InterruptedException {
return eval(env, args, Predicates.<T>alwaysTrue());
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/BinaryOperatorExpression.java b/src/main/java/com/google/devtools/build/lib/query2/engine/BinaryOperatorExpression.java
index e5e600f..2a5cdd8b 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/BinaryOperatorExpression.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/BinaryOperatorExpression.java
@@ -46,7 +46,7 @@
}
@Override
- public <T> Set<T> eval(QueryEnvironment<T> env) throws QueryException {
+ public <T> Set<T> eval(QueryEnvironment<T> env) throws QueryException, InterruptedException {
Set<T> lhsValue = new LinkedHashSet<>(operands.get(0).eval(env));
for (int i = 1; i < operands.size(); i++) {
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/BuildFilesFunction.java b/src/main/java/com/google/devtools/build/lib/query2/engine/BuildFilesFunction.java
index d606a6a..89c4d34 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/BuildFilesFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/BuildFilesFunction.java
@@ -40,7 +40,7 @@
@Override
public <T> Set<T> eval(QueryEnvironment<T> env, QueryExpression expression, List<Argument> args)
- throws QueryException {
+ throws QueryException, InterruptedException {
return env.getBuildFiles(expression, args.get(0).getExpression().eval(env));
}
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/DepsFunction.java b/src/main/java/com/google/devtools/build/lib/query2/engine/DepsFunction.java
index 25b1da7..2a7dc60 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/DepsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/DepsFunction.java
@@ -57,7 +57,7 @@
*/
@Override
public <T> Set<T> eval(QueryEnvironment<T> env, QueryExpression expression, List<Argument> args)
- throws QueryException {
+ throws QueryException, InterruptedException {
Set<T> argumentValue = args.get(0).getExpression().eval(env);
int depthBound = args.size() > 1 ? args.get(1).getInteger() : Integer.MAX_VALUE;
env.buildTransitiveClosure(expression, argumentValue, depthBound);
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/FunctionExpression.java b/src/main/java/com/google/devtools/build/lib/query2/engine/FunctionExpression.java
index 62734fd..b601abb 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/FunctionExpression.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/FunctionExpression.java
@@ -38,7 +38,7 @@
}
@Override
- public <T> Set<T> eval(QueryEnvironment<T> env) throws QueryException {
+ public <T> Set<T> eval(QueryEnvironment<T> env) throws QueryException, InterruptedException {
return function.<T>eval(env, this, args);
}
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/LabelsFunction.java b/src/main/java/com/google/devtools/build/lib/query2/engine/LabelsFunction.java
index 1093d85..e1ad537 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/LabelsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/LabelsFunction.java
@@ -54,7 +54,7 @@
@Override
public <T> Set<T> eval(QueryEnvironment<T> env, QueryExpression expression, List<Argument> args)
- throws QueryException {
+ throws QueryException, InterruptedException {
Set<T> inputs = args.get(1).getExpression().eval(env);
Set<T> result = new LinkedHashSet<>();
String attrName = args.get(0).getWord();
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/LetExpression.java b/src/main/java/com/google/devtools/build/lib/query2/engine/LetExpression.java
index 3e17cce..cc4ec5c 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/LetExpression.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/LetExpression.java
@@ -52,7 +52,7 @@
}
@Override
- public <T> Set<T> eval(QueryEnvironment<T> env) throws QueryException {
+ public <T> Set<T> eval(QueryEnvironment<T> env) throws QueryException, InterruptedException {
if (!NAME_PATTERN.matcher(varName).matches()) {
throw new QueryException(this, "invalid variable name '" + varName + "' in let expression");
}
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/QueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/engine/QueryEnvironment.java
index 78812cc..6dfabfd 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/QueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/QueryEnvironment.java
@@ -123,7 +123,7 @@
* by {@link #getArgumentTypes} and {@link #getMandatoryArguments}
*/
<T> Set<T> eval(QueryEnvironment<T> env, QueryExpression expression, List<Argument> args)
- throws QueryException;
+ throws QueryException, InterruptedException;
}
/**
@@ -176,7 +176,7 @@
*/
void buildTransitiveClosure(QueryExpression caller,
Set<T> targetNodes,
- int maxDepth) throws QueryException;
+ int maxDepth) throws QueryException, InterruptedException;
/**
* Returns the set of nodes on some path from "from" to "to".
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/QueryExpression.java b/src/main/java/com/google/devtools/build/lib/query2/engine/QueryExpression.java
index 23603f1..3e71aac 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/QueryExpression.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/QueryExpression.java
@@ -67,7 +67,8 @@
* thrown. If disabled, evaluation will stumble on to produce a (possibly
* inaccurate) result, but a result nonetheless.
*/
- public abstract <T> Set<T> eval(QueryEnvironment<T> env) throws QueryException;
+ public abstract <T> Set<T> eval(QueryEnvironment<T> env)
+ throws QueryException, InterruptedException;
/**
* Collects all target patterns that are referenced anywhere within this query expression and adds
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/RdepsFunction.java b/src/main/java/com/google/devtools/build/lib/query2/engine/RdepsFunction.java
index 68d0d8b..2f206ce 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/RdepsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/RdepsFunction.java
@@ -54,7 +54,7 @@
*/
@Override
public <T> Set<T> eval(QueryEnvironment<T> env, QueryExpression expression, List<Argument> args)
- throws QueryException {
+ throws QueryException, InterruptedException {
Set<T> universeValue = args.get(0).getExpression().eval(env);
env.buildTransitiveClosure(expression, universeValue, Integer.MAX_VALUE);
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/RegexFilterExpression.java b/src/main/java/com/google/devtools/build/lib/query2/engine/RegexFilterExpression.java
index 1dbe5e6..bce25c5 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/RegexFilterExpression.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/RegexFilterExpression.java
@@ -32,7 +32,7 @@
@Override
public <T> Set<T> eval(QueryEnvironment<T> env, QueryExpression expression, List<Argument> args)
- throws QueryException {
+ throws QueryException, InterruptedException {
Pattern compiledPattern;
try {
compiledPattern = Pattern.compile(getPattern(args));
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/SomeFunction.java b/src/main/java/com/google/devtools/build/lib/query2/engine/SomeFunction.java
index 384b474..4171924 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/SomeFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/SomeFunction.java
@@ -49,7 +49,7 @@
@Override
public <T> Set<T> eval(QueryEnvironment<T> env, QueryExpression expression, List<Argument> args)
- throws QueryException {
+ throws QueryException, InterruptedException {
Set<T> argumentValue = args.get(0).getExpression().eval(env);
if (argumentValue.isEmpty()) {
throw new QueryException(expression, "argument set is empty");
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/SomePathFunction.java b/src/main/java/com/google/devtools/build/lib/query2/engine/SomePathFunction.java
index b90bcdf..820f0f1 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/SomePathFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/SomePathFunction.java
@@ -52,7 +52,7 @@
@Override
public <T> Set<T> eval(QueryEnvironment<T> env, QueryExpression expression, List<Argument> args)
- throws QueryException {
+ throws QueryException, InterruptedException {
Set<T> fromValue = args.get(0).getExpression().eval(env);
Set<T> toValue = args.get(1).getExpression().eval(env);
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/TestsFunction.java b/src/main/java/com/google/devtools/build/lib/query2/engine/TestsFunction.java
index c902609..7249950 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/TestsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/TestsFunction.java
@@ -63,7 +63,7 @@
@Override
public <T> Set<T> eval(QueryEnvironment<T> env, QueryExpression expression, List<Argument> args)
- throws QueryException {
+ throws QueryException, InterruptedException {
Closure<T> closure = new Closure<>(expression, env);
Set<T> result = new HashSet<>();
for (T target : args.get(0).getExpression().eval(env)) {
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/VisibleFunction.java b/src/main/java/com/google/devtools/build/lib/query2/engine/VisibleFunction.java
index f268116..8ce8aa5 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/VisibleFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/VisibleFunction.java
@@ -54,7 +54,7 @@
@Override
public <T> Set<T> eval(QueryEnvironment<T> env, QueryExpression expression, List<Argument> args)
- throws QueryException {
+ throws QueryException, InterruptedException {
Set<T> toSet = args.get(0).getExpression().eval(env);
Set<T> targets = args.get(1).getExpression().eval(env);
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 72ec9ad..2792a15 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
@@ -126,7 +126,7 @@
QueryEvalResult<Target> result;
try {
result = env.evaluateQuery(expr);
- } catch (QueryException e) {
+ } catch (QueryException | InterruptedException e) {
// Keep consistent with reportBuildFileError()
runtime.getReporter().handle(Event.error(e.getMessage()));
return ExitCode.ANALYSIS_FAILURE;