java.lang.Object
org.elasticsearch.ExceptionsHelper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ElasticsearchException
static RuntimeException
static String
formatStackTrace
(StackTraceElement[] stackTrace) static ShardOperationFailedException[]
groupBy
(ShardOperationFailedException[] failures) Deduplicate the failures by exception message and index.static boolean
Utility method useful for determining whether to log an Exception or perhaps avoid logging a stacktrace if the caller/logger is not interested in these types of node/shard issues.static boolean
Checks the exception against a known list of exceptions that indicate a remote cluster cannot be connected to.static boolean
Utility method to check if an Exception is/was caused by TaskCancelledException.static String
limitedStackTrace
(Throwable e, int traceDepth) Constructs a limited and compressed stack trace string.static void
maybeDieOnAnotherThread
(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 boolean
Throws the specified exception.static String
static RestStatus
static Throwable
Looks at the given Throwable and its cause(s) and returns the first Throwable that is of one of the given classes ornull
if no matching Throwable is found.static Throwable
unwrapCausesAndSuppressed
(Throwable cause, Predicate<Throwable> predicate) static IOException
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.static <T extends Throwable>
TuseOrSuppress
(T first, T second)
-
Constructor Details
-
ExceptionsHelper
public ExceptionsHelper()
-
-
Method Details
-
convertToRuntime
-
convertToElastic
-
status
-
unwrapCause
-
stackTrace
-
limitedStackTrace
Constructs a limited and compressed stack trace string. Each exception printed as part of the full stack trace will have its printed stack frames capped at the given trace depth. Stack traces that are longer than the given trace depth will summarize the count of the remaining frames at the end of the trace. Each stack frame omits the module information and limits the package names to single characters per part.
An example result when using a trace depth of 2 and one nested cause:o.e.s.GenericException: some generic exception! at o.e.s.SomeClass.method(SomeClass.java:100) at o.e.s.SomeOtherClass.earlierMethod(SomeOtherClass.java:24) ... 5 more Caused by: o.e.s.GenericException: some other generic exception! at o.e.s.SomeClass.method(SomeClass.java:115) at o.e.s.SomeOtherClass.earlierMethod(SomeOtherClass.java:16) ... 12 more
- Parameters:
e
- Throwable object to construct a printed stack trace fortraceDepth
- The maximum number of stack trace elements to display per exception referenced- Returns:
- A string containing a limited and compressed stack trace.
-
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 ornull
if 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 thentrue
is 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
-
groupBy
Deduplicate the failures by exception message and index.- Parameters:
failures
- array to deduplicate- Returns:
- deduplicated array; if failures is null or empty, it will be returned without modification
-
isTaskCancelledException
Utility method to check if an Exception is/was caused by TaskCancelledException.- Parameters:
e
- Exception we're interested in evaluating.- Returns:
- true if the Exception is/was caused by TaskCancelledException, else false.
-