Class QueryException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- org.apache.druid.query.QueryException
-
- All Implemented Interfaces:
Serializable,SanitizableException
- Direct Known Subclasses:
BadQueryException,QueryCapacityExceededException,QueryInterruptedException,QueryTimeoutException,QueryUnsupportedException
public class QueryException extends RuntimeException implements SanitizableException
Base serializable error response.The Object Model that QueryException follows is a little non-intuitive as the primary way that a QueryException is generated is through a child class. However, those child classes are *not* equivalent to a QueryException, instead they act as a Factory of QueryException objects. This can be seen in two different places.
1. When sanitize() is called, the response is a QueryException without any indication of which original exception occurred. 2. When these objects get serialized across the wire the recipient deserializes a QueryException. The client is never expected, and fundamentally is not allowed to, ever deserialize a child class of QueryException.
For this reason, QueryException must contain all potential state that any of its child classes could ever want to push across the wire. Additionally, any catch clauses expecting one of the child Exceptions must know that it is running inside of code where the exception has not traveled across the wire. If there is a chance that the exception could have been serialized across the wire, the code must catch a QueryException and check the errorCode instead.
As a corollary, adding new state or adjusting the logic of this class must always be done in a backwards-compatible fashion across all child classes of QueryException.
If there is any need to do different logic based on the type of error that has happened, the only reliable method of discerning the type of the error is to look at the errorCode String. Because these Strings are considered part of the API, they are not allowed to change and must maintain their same semantics. The known errorCode Strings are pulled together as public static fields on this class in order to make it more clear what options exist.
QueryResource and SqlResource are expected to emit the JSON form of this object when errors happen.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classQueryException.FailType
-
Field Summary
Fields Modifier and Type Field Description static StringBAD_QUERY_CONTEXT_ERROR_CODEstatic StringJSON_PARSE_ERROR_CODEError codesstatic StringPLAN_VALIDATION_FAILED_ERROR_CODEstatic StringQUERY_CANCELED_ERROR_CODEstatic StringQUERY_CAPACITY_EXCEEDED_ERROR_CODEstatic StringQUERY_INTERRUPTED_ERROR_CODEstatic StringQUERY_TIMEOUT_ERROR_CODEstatic StringQUERY_UNSUPPORTED_ERROR_CODEstatic StringRESOURCE_LIMIT_EXCEEDED_ERROR_CODEstatic StringSQL_PARSE_FAILED_ERROR_CODEstatic StringSQL_QUERY_UNSUPPORTED_ERROR_CODEstatic StringTRUNCATED_RESPONSE_CONTEXT_ERROR_CODEstatic StringUNAUTHORIZED_ERROR_CODEstatic StringUNKNOWN_EXCEPTION_ERROR_CODEstatic StringUNSUPPORTED_OPERATION_ERROR_CODE
-
Constructor Summary
Constructors Modifier Constructor Description QueryException(String errorCode, String errorMessage, String errorClass, String host)protectedQueryException(Throwable cause, String errorCode, String errorClass, String host)protectedQueryException(Throwable cause, String errorCode, String errorMessage, String errorClass, String host)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static QueryException.FailTypefromErrorCode(String errorCode)StringgetErrorClass()StringgetErrorCode()QueryException.FailTypegetFailType()StringgetHost()StringgetMessage()protected static StringresolveHostname()QueryExceptionsanitize(@NotNull Function<String,String> errorMessageTransformFunction)Apply the function for transforming the error message then return new Exception with sanitized fields and transformed message.StringtoString()-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
-
-
-
-
Field Detail
-
JSON_PARSE_ERROR_CODE
public static final String JSON_PARSE_ERROR_CODE
Error codes- See Also:
- Constant Field Values
-
BAD_QUERY_CONTEXT_ERROR_CODE
public static final String BAD_QUERY_CONTEXT_ERROR_CODE
- See Also:
- Constant Field Values
-
QUERY_CAPACITY_EXCEEDED_ERROR_CODE
public static final String QUERY_CAPACITY_EXCEEDED_ERROR_CODE
- See Also:
- Constant Field Values
-
QUERY_INTERRUPTED_ERROR_CODE
public static final String QUERY_INTERRUPTED_ERROR_CODE
- See Also:
- Constant Field Values
-
QUERY_CANCELED_ERROR_CODE
public static final String QUERY_CANCELED_ERROR_CODE
- See Also:
- Constant Field Values
-
UNAUTHORIZED_ERROR_CODE
public static final String UNAUTHORIZED_ERROR_CODE
- See Also:
- Constant Field Values
-
UNSUPPORTED_OPERATION_ERROR_CODE
public static final String UNSUPPORTED_OPERATION_ERROR_CODE
- See Also:
- Constant Field Values
-
TRUNCATED_RESPONSE_CONTEXT_ERROR_CODE
public static final String TRUNCATED_RESPONSE_CONTEXT_ERROR_CODE
- See Also:
- Constant Field Values
-
UNKNOWN_EXCEPTION_ERROR_CODE
public static final String UNKNOWN_EXCEPTION_ERROR_CODE
- See Also:
- Constant Field Values
-
QUERY_TIMEOUT_ERROR_CODE
public static final String QUERY_TIMEOUT_ERROR_CODE
- See Also:
- Constant Field Values
-
QUERY_UNSUPPORTED_ERROR_CODE
public static final String QUERY_UNSUPPORTED_ERROR_CODE
- See Also:
- Constant Field Values
-
RESOURCE_LIMIT_EXCEEDED_ERROR_CODE
public static final String RESOURCE_LIMIT_EXCEEDED_ERROR_CODE
- See Also:
- Constant Field Values
-
SQL_PARSE_FAILED_ERROR_CODE
public static final String SQL_PARSE_FAILED_ERROR_CODE
- See Also:
- Constant Field Values
-
PLAN_VALIDATION_FAILED_ERROR_CODE
public static final String PLAN_VALIDATION_FAILED_ERROR_CODE
- See Also:
- Constant Field Values
-
SQL_QUERY_UNSUPPORTED_ERROR_CODE
public static final String SQL_QUERY_UNSUPPORTED_ERROR_CODE
- See Also:
- Constant Field Values
-
-
Method Detail
-
fromErrorCode
public static QueryException.FailType fromErrorCode(String errorCode)
-
getMessage
public String getMessage()
- Overrides:
getMessagein classThrowable
-
getErrorClass
public String getErrorClass()
-
getHost
public String getHost()
-
sanitize
public QueryException sanitize(@NotNull @NotNull Function<String,String> errorMessageTransformFunction)
Description copied from interface:SanitizableExceptionApply the function for transforming the error message then return new Exception with sanitized fields and transformed message. The {@param errorMessageTransformFunction} is only intended to be use to transform the error message String of the Exception as only the error message String is common to all Exception classes. For other fields (which may be unique to each particular Exception class), each implementation of this method can decide for itself how to sanitized those fields (i.e. leaving unchanged, changing to null, changing to a fixed String, etc.). Note that this method returns a new Exception of the same type since Exception error message is immutable.- Specified by:
sanitizein interfaceSanitizableException
-
getFailType
public QueryException.FailType getFailType()
-
-