Package com.tnsai.tools.spi
Class ToolException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
com.tnsai.exceptions.TnsAIException
com.tnsai.tools.spi.ToolException
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ToolAuthenticationException,ToolAuthorizationException,ToolConfigurationException,ToolConflictException,ToolExternalServiceException,ToolInputException,ToolNotFoundException,ToolRateLimitException,ToolResultSerializationException,ToolTimeoutException,ToolUnexpectedException,ToolUserCanceledException
Exception thrown when a tool execution fails.
Provides structured error information including:
- Error type classification (
ToolException.ErrorType) - Tool name and query that caused the error
- HTTP status code (for API errors)
- Retry eligibility flag
- Timestamp of the error
- Additional context attributes
Usage Example
// Simple usage
throw new ToolException("API rate limit exceeded", ErrorType.RATE_LIMITED);
// Full context
throw ToolException.builder("Connection timeout")
.type(ErrorType.TIMEOUT)
.toolName("brave_search")
.query("quantum computing")
.retryable(true)
.attribute("timeout_ms", 30000)
.build();
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for ToolException.static enumError type classification. -
Constructor Summary
ConstructorsConstructorDescriptionToolException(String message) Create a simple tool exception.ToolException(String message, ToolException.ErrorType errorType) Create a tool exception with error type.ToolException(String message, ToolException.ErrorType errorType, Throwable cause) Create a tool exception with error type and cause.ToolException(String message, Throwable cause) Create a tool exception with cause. -
Method Summary
Modifier and TypeMethodDescriptionstatic ToolExceptionCreate an API error.static ToolException.BuilderCreate a builder for ToolException.static ToolExceptionconfigurationError(String toolName, String envVar) Create a configuration error (e.g., missing API key).<T> TgetAttribute(String key) Get a detailed error message including all context.intgetQuery()booleanChecks if this error is retryable.static ToolExceptionnetworkError(String toolName, Throwable cause) Create a network error.static ToolExceptionparseError(String toolName, String message, Throwable cause) Create a parse error.static ToolExceptionCreate a timeout error.toString()static ToolExceptionvalidationError(String toolName, String message) Create a validation error.Methods inherited from class com.tnsai.exceptions.TnsAIException
getContext, getErrorCode, getMaxRetryAttempts, getMessage, getSuggestedRetryDelayMs, getThrownAt, wrapMethods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
-
Constructor Details
-
ToolException
Create a simple tool exception. -
ToolException
Create a tool exception with cause. -
ToolException
Create a tool exception with error type. -
ToolException
Create a tool exception with error type and cause.
-
-
Method Details
-
builder
Create a builder for ToolException. -
validationError
Create a validation error. -
configurationError
Create a configuration error (e.g., missing API key). -
apiError
Create an API error. -
timeout
Create a timeout error. -
networkError
Create a network error. -
parseError
Create a parse error. -
getErrorType
-
getToolName
-
getQuery
-
getHttpStatusCode
public int getHttpStatusCode() -
isRetryable
public boolean isRetryable()Description copied from class:TnsAIExceptionChecks if this error is retryable. Retryable errors are typically transient (network issues, rate limits, server errors).- Overrides:
isRetryablein classTnsAIException- Returns:
- true if the operation can be retried
-
getTimestamp
-
getAttributes
-
getAttribute
-
getDetailedMessage
Get a detailed error message including all context. -
toString
-