Package org.opensearch
Class ExceptionsHelper
java.lang.Object
org.opensearch.ExceptionsHelper
Helper class for OpenSearch Exceptions
- Opensearch.internal:
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcatchAsRuntimeException(org.opensearch.common.CheckedRunnable<Exception> runnable) Run passed runnable and catch exception and translate exception into runtime exception usingconvertToRuntime(Exception)static <R,E extends Exception>
RcatchAsRuntimeException(org.opensearch.common.CheckedSupplier<R, E> supplier) Run passed runnable and catch exception and translate exception into runtime exception usingconvertToRuntime(Exception)static OpenSearchExceptionstatic RuntimeExceptionstatic StringDeprecated.Don't swallow exceptions, allow them to propagate.static StringformatStackTrace(StackTraceElement[] stackTrace) static ShardOperationFailedException[]groupBy(ShardOperationFailedException[] failures) Deduplicate the failures by exception message and index.static voidmaybeDieOnAnotherThread(Throwable throwable) If the specified cause is an unrecoverable error, this method will rethrow the cause on a separate thread so that it can not be caught and bubbles up to the uncaught exception handler.maybeError(Throwable cause) Unwrap the specified throwable looking for any suppressed errors or errors as a root cause of the specified throwable.static <T extends Throwable>
voidmaybeThrowRuntimeAndSuppress(List<T> exceptions) Throws a runtime exception with all given exceptions added as suppressed.static <T extends Throwable>
voidrethrowAndSuppress(List<T> exceptions) Rethrows the first exception in the list and adds all remaining to the suppressed list.static booleanThrows the specified exception.static Stringstatic RestStatusstatic Stringstatic ThrowableLooks at the given Throwable and its cause(s) and returns the first Throwable that is of one of the given classes ornullif no matching Throwable is found.static ThrowableunwrapCausesAndSuppressed(Throwable cause, Predicate<Throwable> predicate) static IOExceptionLooks at the given Throwable's and its cause(s) as well as any suppressed exceptions on the Throwable as well as its causes and returns the first corruption indicating exception (as defined byCORRUPTION_EXCEPTIONS) it finds.static <T extends Throwable>
TuseOrSuppress(T first, T second)
-
Method Details
-
convertToRuntime
-
convertToOpenSearchException
-
status
-
summaryMessage
-
unwrapCause
-
detailedMessage
Deprecated.Don't swallow exceptions, allow them to propagate. -
stackTrace
-
formatStackTrace
-
rethrowAndSuppress
Rethrows the first exception in the list and adds all remaining to the suppressed list. If the given list is empty no exception is thrown- Throws:
T
-
maybeThrowRuntimeAndSuppress
Throws a runtime exception with all given exceptions added as suppressed. If the given list is empty no exception is thrown -
useOrSuppress
-
unwrapCorruption
Looks at the given Throwable's and its cause(s) as well as any suppressed exceptions on the Throwable as well as its causes and returns the first corruption indicating exception (as defined byCORRUPTION_EXCEPTIONS) it finds.- Parameters:
t- Throwable- Returns:
- Corruption indicating exception if one is found, otherwise
null
-
unwrap
Looks at the given Throwable and its cause(s) and returns the first Throwable that is of one of the given classes ornullif no matching Throwable is found. UnlikeunwrapCorruption(java.lang.Throwable)this method does only check the given Throwable and its causes but does not look at any suppressed exceptions.- Parameters:
t- Throwableclazzes- Classes to look for- Returns:
- Matching Throwable if one is found, otherwise
null
-
reThrowIfNotNull
Throws the specified exception. If null if specified thentrueis returned. -
unwrapCausesAndSuppressed
-
maybeError
Unwrap the specified throwable looking for any suppressed errors or errors as a root cause of the specified throwable.- Parameters:
cause- the root throwable- Returns:
- an optional error if one is found suppressed or a root cause in the tree rooted at the specified throwable
-
maybeDieOnAnotherThread
If the specified cause is an unrecoverable error, this method will rethrow the cause on a separate thread so that it can not be caught and bubbles up to the uncaught exception handler. Note that the cause tree is examined for anyError. SeemaybeError(Throwable)for the semantics.- Parameters:
throwable- the throwable to possibly throw on another thread
-
catchAsRuntimeException
public static <R,E extends Exception> R catchAsRuntimeException(org.opensearch.common.CheckedSupplier<R, E> supplier) Run passed runnable and catch exception and translate exception into runtime exception usingconvertToRuntime(Exception)- Parameters:
supplier- to run
-
catchAsRuntimeException
public static void catchAsRuntimeException(org.opensearch.common.CheckedRunnable<Exception> runnable) Run passed runnable and catch exception and translate exception into runtime exception usingconvertToRuntime(Exception)- Parameters:
runnable- to run
-
groupBy
Deduplicate the failures by exception message and index.
-