[NO ISSUE][*DB] += exception helper method
Change-Id: I7d7aee2fb2bb25a59d2825761b127f969348666b
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/8163
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ExceptionUtils.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ExceptionUtils.java
index 359054e..1f42771 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ExceptionUtils.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ExceptionUtils.java
@@ -21,6 +21,7 @@
import java.util.function.Predicate;
import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.exceptions.IFormattedException;
public class ExceptionUtils {
public static final String INCORRECT_PARAMETER = "Incorrect parameter.\n";
@@ -85,4 +86,18 @@
}
return test.test(e);
}
+
+ /**
+ * Unwraps enclosed exceptions until a non-product exception is found, otherwise returns the root production
+ * exception
+ */
+ public static Throwable unwrap(Throwable e) {
+ Throwable current = e;
+ Throwable cause = e.getCause();
+ while (cause != null && cause != current && current instanceof IFormattedException) {
+ current = cause;
+ cause = current.getCause();
+ }
+ return current;
+ }
}