Package org.opensearch
Class OpenSearchException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.opensearch.OpenSearchException
- All Implemented Interfaces:
Serializable,Writeable,ToXContent,ToXContentFragment
- Direct Known Subclasses:
CircuitBreakingException,IndexShardSnapshotException,NotSerializableExceptionWrapper,OpenSearchParseException,ParsingException,TaskCancelledException
@PublicApi(since="1.0.0")
public class OpenSearchException
extends RuntimeException
implements Writeable, ToXContentFragment
A core library base class for all opensearch exceptions.
- See Also:
- Opensearch.api:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classThis is the list of Exceptions OpenSearch can throw over the wire or save into a corruption marker.static classRegistry of ExceptionHandlersNested classes/interfaces inherited from interface org.opensearch.core.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.ParamsNested classes/interfaces inherited from interface org.opensearch.core.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.WriteableRegistry, Writeable.Writer<V> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringPassed in theToXContent.ParamsofgenerateThrowableXContent(XContentBuilder, ToXContent.Params, Throwable)to control if thestack_traceelement should render.static final booleanstatic final Stringprotected static final VersionFields inherited from interface org.opensearch.core.xcontent.ToXContent
EMPTY_PARAMS -
Constructor Summary
ConstructorsConstructorDescriptionOpenSearchException(String msg, Object... args) Construct aOpenSearchExceptionwith the specified detail message.OpenSearchException(String msg, Throwable cause, Object... args) Construct aOpenSearchExceptionwith the specified detail message and nested exception.OpenSearchException(Throwable cause) Construct aOpenSearchExceptionwith the specified cause exception. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a new header with the given key.voidAdds a new header with the given key.voidaddMetadata(String key, String... values) Adds a new piece of metadata with the given key.voidaddMetadata(String key, List<String> values) Adds a new piece of metadata with the given key.static OpenSearchExceptionfailureFromXContent(XContentParser parser) Parses the output ofgenerateFailureXContent(XContentBuilder, Params, Exception, boolean)static OpenSearchExceptionfromXContent(XContentParser parser) Generate aOpenSearchExceptionfrom aXContentParser.static voidgenerateFailureXContent(XContentBuilder builder, ToXContent.Params params, Exception e, boolean detailed) Render any exception as a xcontent, encapsulated within a field or object named "error".static voidgenerateThrowableXContent(XContentBuilder builder, ToXContent.Params params, Throwable t) Static toXContent helper method that rendersOpenSearchExceptionorThrowableinstances as XContent, delegating the rendering totoXContent(XContentBuilder, ToXContent.Params)orinnerToXContent(XContentBuilder, ToXContent.Params, Throwable, String, String, Map, Map, Throwable).Return the detail message, including the message from the nested exception if there is one.protected Stringstatic StringReturns an underscore case name for the given exception.static StringReturns the list of header values for the given key ornullif no header for the given key exists.Returns a set of all header keys on this exceptionstatic intgetId(Class<? extends OpenSearchException> exception) Returns the serialization id the given exception.getIndex()getMetadata(String key) Returns the list of metadata values for the given key ornullif no metadata for the given key exists.Returns a set of all metadata keys on this exceptionRetrieve the innermost cause of this exception, if none, returns the current exception.Returns the root cause of this exception or multiple if different shards caused different exceptionsstatic OpenSearchException[]Returns the root cause of this exception or multiple if different shards caused different exceptions.protected static voidheaderToXContent(XContentBuilder builder, String key, List<String> values) static OpenSearchExceptioninnerFromXContent(XContentParser parser, boolean parseRootCauses) protected static voidinnerToXContent(XContentBuilder builder, ToXContent.Params params, Throwable throwable, String type, String message, Map<String, List<String>> headers, Map<String, List<String>> metadata, Throwable cause) static booleanisRegistered(Class<? extends Throwable> exception, Version version) Returnstrueiff the given class is a registered for an exception to be read.protected voidmetadataToXContent(XContentBuilder builder, ToXContent.Params params) Renders additional per exception information into the XContentstatic <T extends StreamInput>
OpenSearchExceptionreadException(T input, int id) static <T extends Throwable>
TreadStackTrace(T throwable, StreamInput in) Deserializes stacktrace elements as well as suppressed exceptions from the given output stream and adds it to the given exception.voidvoidvoidsetResources(String type, String... id) voidstatus()Returns the rest status code associated with this exception.toString()toXContent(XContentBuilder builder, ToXContent.Params params) Unwraps the actual cause from the exception for cases when the exception is aOpenSearchWrapperException.static <S extends StreamOutput,T extends Throwable>
TwriteStackTraces(T throwable, StreamOutput out, Writeable.Writer<Throwable> exceptionWriter) Serializes the given exceptions stacktrace elements as well as it's suppressed exceptions to the given output stream.voidwriteTo(StreamOutput out) Write this into the StreamOutput.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTraceMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.opensearch.core.xcontent.ToXContentFragment
isFragment
-
Field Details
-
UNKNOWN_VERSION_ADDED
-
REST_EXCEPTION_SKIP_STACK_TRACE
Passed in theToXContent.ParamsofgenerateThrowableXContent(XContentBuilder, ToXContent.Params, Throwable)to control if thestack_traceelement should render. Unlike most parameters totoXContentmethods this parameter is internal only and not available as a URL parameter. Use theerror_traceparameter instead.- See Also:
-
REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT
public static final boolean REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT- See Also:
-
STACK_TRACE
- See Also:
-
metadata
-
headers
-
-
Constructor Details
-
OpenSearchException
Construct aOpenSearchExceptionwith the specified cause exception. -
OpenSearchException
Construct aOpenSearchExceptionwith the specified detail message.The message can be parameterized using
{}as placeholders for the given arguments- Parameters:
msg- the detail messageargs- the arguments for the message
-
OpenSearchException
Construct aOpenSearchExceptionwith the specified detail message and nested exception.The message can be parameterized using
{}as placeholders for the given arguments- Parameters:
msg- the detail messagecause- the nested exceptionargs- the arguments for the message
-
OpenSearchException
- Throws:
IOException
-
-
Method Details
-
writeTo
Description copied from interface:WriteableWrite this into the StreamOutput.- Specified by:
writeToin interfaceWriteable- Throws:
IOException
-
addMetadata
Adds a new piece of metadata with the given key. If the provided key is already present, the corresponding metadata will be replaced -
addMetadata
Adds a new piece of metadata with the given key. If the provided key is already present, the corresponding metadata will be replaced -
getMetadataKeys
Returns a set of all metadata keys on this exception -
getMetadata
Returns the list of metadata values for the given key ornullif no metadata for the given key exists. -
getMetadata
-
addHeader
Adds a new header with the given key. This method will replace existing header if a header with the same key already exists -
addHeader
Adds a new header with the given key. This method will replace existing header if a header with the same key already exists -
getHeaderKeys
Returns a set of all header keys on this exception -
getHeader
Returns the list of header values for the given key ornullif no header for the given key exists. -
getHeaders
-
status
Returns the rest status code associated with this exception. -
unwrapCause
Unwraps the actual cause from the exception for cases when the exception is aOpenSearchWrapperException.- See Also:
-
getDetailedMessage
Return the detail message, including the message from the nested exception if there is one. -
getRootCause
Retrieve the innermost cause of this exception, if none, returns the current exception. -
readException
public static <T extends StreamInput> OpenSearchException readException(T input, int id) throws IOException - Throws:
IOException
-
isRegistered
Returnstrueiff the given class is a registered for an exception to be read. -
getId
Returns the serialization id the given exception. -
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException - Specified by:
toXContentin interfaceToXContent- Throws:
IOException
-
innerToXContent
protected static void innerToXContent(XContentBuilder builder, ToXContent.Params params, Throwable throwable, String type, String message, Map<String, List<String>> headers, Map<String, throws IOExceptionList<String>> metadata, Throwable cause) - Throws:
IOException
-
headerToXContent
protected static void headerToXContent(XContentBuilder builder, String key, List<String> values) throws IOException - Throws:
IOException
-
metadataToXContent
protected void metadataToXContent(XContentBuilder builder, ToXContent.Params params) throws IOException Renders additional per exception information into the XContent- Throws:
IOException
-
fromXContent
Generate aOpenSearchExceptionfrom aXContentParser. This does not return the original exception type (ie NodeClosedException for example) but just wraps the type, the reason and the cause of the exception. It also recursively parses the tree structure of the cause, returning it as a tree structure ofOpenSearchExceptioninstances.- Throws:
IOException
-
innerFromXContent
public static OpenSearchException innerFromXContent(XContentParser parser, boolean parseRootCauses) throws IOException - Throws:
IOException
-
generateThrowableXContent
public static void generateThrowableXContent(XContentBuilder builder, ToXContent.Params params, Throwable t) throws IOException Static toXContent helper method that rendersOpenSearchExceptionorThrowableinstances as XContent, delegating the rendering totoXContent(XContentBuilder, ToXContent.Params)orinnerToXContent(XContentBuilder, ToXContent.Params, Throwable, String, String, Map, Map, Throwable).This method is usually used when the
Throwableis rendered as a part of another XContent object, and its result can be parsed back using theOpenSearchException.fromXContent(XContentParser)method.- Throws:
IOException
-
generateFailureXContent
public static void generateFailureXContent(XContentBuilder builder, ToXContent.Params params, @Nullable Exception e, boolean detailed) throws IOException Render any exception as a xcontent, encapsulated within a field or object named "error". The level of details that are rendered depends on the value of the "detailed" parameter: when it's false only a simple message based on the type and message of the exception is rendered. When it's true all detail are provided including guesses root causes, cause and potentially stack trace.This method is usually used when the
Exceptionis rendered as a full XContent object, and its output can be parsed by the#OpenSearchException.failureFromXContent(XContentParser)method.- Throws:
IOException
-
failureFromXContent
Parses the output ofgenerateFailureXContent(XContentBuilder, Params, Exception, boolean)- Throws:
IOException
-
guessRootCauses
Returns the root cause of this exception or multiple if different shards caused different exceptions -
guessRootCauses
Returns the root cause of this exception or multiple if different shards caused different exceptions. If the given exception is not an instance ofOpenSearchExceptionan empty array is returned. -
getExceptionName
-
getExceptionName
Returns an underscore case name for the given exception. This method stripsOpenSearchprefixes from exception names. -
getExceptionSimpleClassName
-
toString
-
readStackTrace
public static <T extends Throwable> T readStackTrace(T throwable, StreamInput in) throws IOException Deserializes stacktrace elements as well as suppressed exceptions from the given output stream and adds it to the given exception.- Throws:
IOException
-
writeStackTraces
public static <S extends StreamOutput,T extends Throwable> T writeStackTraces(T throwable, StreamOutput out, Writeable.Writer<Throwable> exceptionWriter) throws IOException Serializes the given exceptions stacktrace elements as well as it's suppressed exceptions to the given output stream.- Throws:
IOException
-
setResources
-
getResourceId
-
getResourceType
-
getIndex
-
setIndex
-
setIndex
-
getShardId
-
setShard
-