Skip to content

Commit

Permalink
BEGIN_PUBLIC
Browse files Browse the repository at this point in the history
Migrate from soon-to-be-deprecated `propagateIfPossible` to equivalent `throwIfInstanceOf` and `throwIfUnchecked` calls.
END_PUBLIC

PiperOrigin-RevId: 613891830
Change-Id: I14d8ae6ff217ff2c183342a8c74f92c410206500
  • Loading branch information
cpovirk authored and copybara-github committed Mar 8, 2024
1 parent 8e37fe9 commit 85d585d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
// limitations under the License.
package com.google.devtools.build.lib.packages;

import static com.google.common.base.Throwables.throwIfInstanceOf;
import static com.google.common.base.Throwables.throwIfUnchecked;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.SettableFuture;
Expand Down Expand Up @@ -239,7 +241,9 @@ private static List<Path> fromFuture(Future<List<Path>> future)
return future.get();
} catch (ExecutionException e) {
Throwable cause = e.getCause();
Throwables.propagateIfPossible(cause, IOException.class, InterruptedException.class);
throwIfInstanceOf(cause, IOException.class);
throwIfInstanceOf(cause, InterruptedException.class);
throwIfUnchecked(cause);
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// limitations under the License.
package com.google.devtools.build.lib.query2.aquery;

import static com.google.common.base.Throwables.throwIfInstanceOf;
import static com.google.common.base.Throwables.throwIfUnchecked;

import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.actions.CommandLineExpansionException;
Expand Down Expand Up @@ -179,8 +182,9 @@ private void processOutputInParallel(Iterable<ConfiguredTargetValue> partialResu
// TODO(b/266179316): Clean this up.
throw new IOException(cause.getMessage());
}
Throwables.propagateIfPossible(cause, IOException.class);
Throwables.propagateIfPossible(cause, InterruptedException.class);
throwIfInstanceOf(cause, IOException.class);
throwIfInstanceOf(cause, InterruptedException.class);
throwIfUnchecked(cause);
throw new IllegalStateException("Unexpected exception type: ", e);
} finally {
executor.shutdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
// limitations under the License.
package com.google.devtools.build.lib.query2.common;

import static com.google.common.base.Throwables.throwIfInstanceOf;
import static com.google.common.base.Throwables.throwIfUnchecked;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;

import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicates;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
Expand Down Expand Up @@ -694,8 +695,9 @@ private T getChecked() throws InterruptedException, QueryException {
throw new InterruptedException();
} catch (ExecutionException e) {
Throwable cause = e.getCause();
Throwables.propagateIfPossible(cause, QueryException.class);
Throwables.propagateIfPossible(cause, InterruptedException.class);
throwIfInstanceOf(cause, QueryException.class);
throwIfInstanceOf(cause, InterruptedException.class);
throwIfUnchecked(cause);
throw new IllegalStateException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
// limitations under the License.
package com.google.devtools.build.lib.skyframe;

import static com.google.common.base.Throwables.throwIfInstanceOf;
import static com.google.common.base.Throwables.throwIfUnchecked;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
Expand Down Expand Up @@ -575,10 +578,11 @@ public void dumpSkyframeStateInParallel(
} catch (ExecutionException e) {
aqueryConsumingOutputHandler.stopConsumer(/* discardRemainingTasks= */ true);
Throwable cause = Throwables.getRootCause(e);
Throwables.propagateIfPossible(cause, CommandLineExpansionException.class);
Throwables.propagateIfPossible(cause, TemplateExpansionException.class);
Throwables.propagateIfPossible(cause, IOException.class);
Throwables.propagateIfPossible(cause, InterruptedException.class);
throwIfInstanceOf(cause, CommandLineExpansionException.class);
throwIfInstanceOf(cause, TemplateExpansionException.class);
throwIfInstanceOf(cause, IOException.class);
throwIfInstanceOf(cause, InterruptedException.class);
throwIfUnchecked(cause);
throw new IllegalStateException("Unexpected exception type: ", e);
} finally {
executor.shutdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Throwables.throwIfInstanceOf;
import static com.google.common.base.Throwables.throwIfUnchecked;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
Expand Down Expand Up @@ -893,8 +895,9 @@ public final SkyValue evaluateSkyKeyForExecutionSetup(
return checkNotNull(result.get(key), "%s %s", result, key);
}
ErrorInfo errorInfo = checkNotNull(result.getError(key), "%s %s", key, result);
Throwables.propagateIfPossible(errorInfo.getException(), EnvironmentalExecException.class);
if (errorInfo.getException() != null) {
throwIfInstanceOf(errorInfo.getException(), EnvironmentalExecException.class);
throwIfUnchecked(errorInfo.getException());
throw new IllegalStateException(errorInfo.getException());
}
throw new IllegalStateException(errorInfo.toString());
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@

package com.google.devtools.build.lib.vfs;

import static com.google.common.base.Throwables.throwIfInstanceOf;
import static com.google.common.base.Throwables.throwIfUnchecked;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -478,7 +480,8 @@ List<Path> glob(
return globAsync(base, patterns, pathDiscriminator, syscalls).get();
} catch (ExecutionException e) {
Throwable cause = e.getCause();
Throwables.propagateIfPossible(cause, IOException.class);
throwIfInstanceOf(cause, IOException.class);
throwIfUnchecked(cause);
throw new RuntimeException(e);
}
}
Expand All @@ -494,8 +497,9 @@ List<Path> globUninterruptible(
globAsync(base, patterns, pathDiscriminator, syscalls));
} catch (ExecutionException e) {
Throwable cause = e.getCause();
Throwables.propagateIfPossible(cause, IOException.class);
Throwables.propagateIfPossible(cause, BadPattern.class);
throwIfInstanceOf(cause, IOException.class);
throwIfInstanceOf(cause, BadPattern.class);
throwIfUnchecked(cause);
throw new RuntimeException(e);
}
}
Expand Down

0 comments on commit 85d585d

Please sign in to comment.