scwhittle commented on code in PR #40955:
URL: https://github.com/apache/beam/pull/40955#discussion_r4543562364


##########
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/util/ExceptionUtils.java:
##########
@@ -40,4 +45,54 @@ public static RuntimeException 
safeWrapThrowableAsException(Throwable throwable)
       return new RuntimeException(throwable);
     }
   }
+
+  /**
+   * Returns whether {@code throwable} or any of its causes is an instance of 
{@code
+   * exceptionClass}.
+   */
+  public static boolean hasCause(
+      @Nullable Throwable throwable, Class<? extends Throwable> 
exceptionClass) {
+    return hasAnyCause(throwable, exceptionClass::isInstance);
+  }
+
+  /**
+   * Returns whether {@code throwable} or any of its causes is an instance of 
either {@code
+   * exceptionClass1} or {@code exceptionClass2}.
+   */
+  public static boolean hasCause(
+      @Nullable Throwable throwable,
+      Class<? extends Throwable> exceptionClass1,
+      Class<? extends Throwable> exceptionClass2) {
+    return hasAnyCause(
+        throwable, t -> exceptionClass1.isInstance(t) || 
exceptionClass2.isInstance(t));
+  }
+
+  /** Returns whether {@code throwable} or any of its causes matches the given 
{@code predicate}. */
+  public static boolean hasAnyCause(@Nullable Throwable throwable, 
Predicate<Throwable> predicate) {

Review Comment:
   how about hasMatchingCause? hasAnyCause is confusing to me



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to