pub enum ToolError {
Retriable {
source: Option<Arc<dyn Error + Send + Sync>>,
source_message: String,
context: String,
},
RateLimited {
source: Option<Arc<dyn Error + Send + Sync>>,
source_message: String,
context: String,
retry_after: Option<Duration>,
},
Permanent {
source: Option<Arc<dyn Error + Send + Sync>>,
source_message: String,
context: String,
},
InvalidInput {
source: Option<Arc<dyn Error + Send + Sync>>,
source_message: String,
context: String,
},
SignerContext(String),
}Expand description
Tool-specific error type for distinguishing retriable vs permanent failures.
Variants§
Retriable
Operation can be retried
Fields
RateLimited
Rate limited, retry after delay
Fields
Permanent
Permanent error, do not retry
Fields
InvalidInput
Invalid input provided
Fields
SignerContext(String)
Signer context error
Implementations§
Source§impl ToolError
impl ToolError
Sourcepub fn retriable_with_source<E: Error + Send + Sync + 'static>(
source: E,
context: impl Into<String>,
) -> Self
pub fn retriable_with_source<E: Error + Send + Sync + 'static>( source: E, context: impl Into<String>, ) -> Self
Creates a retriable error with context and source preservation
Sourcepub fn permanent_with_source<E: Error + Send + Sync + 'static>(
source: E,
context: impl Into<String>,
) -> Self
pub fn permanent_with_source<E: Error + Send + Sync + 'static>( source: E, context: impl Into<String>, ) -> Self
Creates a permanent error with context and source preservation
Sourcepub fn rate_limited_with_source<E: Error + Send + Sync + 'static>(
source: E,
context: impl Into<String>,
retry_after: Option<Duration>,
) -> Self
pub fn rate_limited_with_source<E: Error + Send + Sync + 'static>( source: E, context: impl Into<String>, retry_after: Option<Duration>, ) -> Self
Creates a rate limited error with optional retry duration
Sourcepub fn invalid_input_with_source<E: Error + Send + Sync + 'static>(
source: E,
context: impl Into<String>,
) -> Self
pub fn invalid_input_with_source<E: Error + Send + Sync + 'static>( source: E, context: impl Into<String>, ) -> Self
Creates an invalid input error
Sourcepub const fn is_retriable(&self) -> bool
pub const fn is_retriable(&self) -> bool
Returns whether this error is retriable
Sourcepub const fn retry_after(&self) -> Option<Duration>
pub const fn retry_after(&self) -> Option<Duration>
Returns the retry delay if this is a rate limited error
Sourcepub const fn is_rate_limited(&self) -> bool
pub const fn is_rate_limited(&self) -> bool
Checks if the error is rate limited (for compatibility)
Sourcepub fn retriable_string<S: Into<String>>(msg: S) -> Self
pub fn retriable_string<S: Into<String>>(msg: S) -> Self
Creates a retriable error from a string message
Sourcepub fn permanent_string<S: Into<String>>(msg: S) -> Self
pub fn permanent_string<S: Into<String>>(msg: S) -> Self
Creates a permanent error from a string message
Sourcepub fn rate_limited_string<S: Into<String>>(msg: S) -> Self
pub fn rate_limited_string<S: Into<String>>(msg: S) -> Self
Creates a rate limited error from a string message
Sourcepub fn invalid_input_string<S: Into<String>>(msg: S) -> Self
pub fn invalid_input_string<S: Into<String>>(msg: S) -> Self
Creates an invalid input error from a string message
Sourcepub fn contains(&self, needle: &str) -> bool
pub fn contains(&self, needle: &str) -> bool
Check if the error contains a specific substring in its string representation
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ToolError
impl<'de> Deserialize<'de> for ToolError
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Error for ToolError
impl Error for ToolError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<Error> for ToolError
§Error Classification: Explicit is Better
Generic From implementations for common error types like anyhow::Error and String
have been intentionally removed. This is a deliberate design choice to enforce
explicit error classification at the point of creation.
impl From<Error> for ToolError
§Error Classification: Explicit is Better
Generic From implementations for common error types like anyhow::Error and String
have been intentionally removed. This is a deliberate design choice to enforce
explicit error classification at the point of creation.
Automatically classifying unknown errors as Permanent is a safe default but can hide
bugs where transient, retriable errors are not handled correctly. By requiring
explicit classification, developers are forced to make a conscious decision about
the nature of the error.
§Best Practices
Always use the explicit constructors to create ToolError instances:
use riglr_core::ToolError;
use std::io::Error as IoError;
// ✅ Explicitly classify known transient errors as retriable.
let network_error = IoError::new(std::io::ErrorKind::TimedOut, "Connection timeout");
let tool_error = ToolError::retriable_with_source(network_error, "API call failed");
// ✅ Explicitly classify rate limiting errors.
let rate_limit_error = IoError::new(std::io::ErrorKind::Other, "Rate limited");
let tool_error = ToolError::rate_limited_with_source(
rate_limit_error,
"API rate limit exceeded",
Some(std::time::Duration::from_secs(60))
);
// ✅ Explicitly classify user input errors.
let input_error = IoError::new(std::io::ErrorKind::InvalidInput, "Bad address");
let tool_error = ToolError::invalid_input_with_source(input_error, "Invalid address format");
// ✅ Explicitly classify all other unrecoverable errors as permanent.
let auth_error = IoError::new(std::io::ErrorKind::PermissionDenied, "Invalid API key");
let tool_error = ToolError::permanent_with_source(auth_error, "Authentication failed");