#[derive(Debug, Clone, thiserror::Error)]
pub enum ProviderError {
#[error("Authentication failed for {provider}: {message}")]
Authentication {
provider: &'static str,
message: String,
},
#[error("Rate limit exceeded for {provider}: {message}")]
RateLimit {
provider: &'static str,
message: String,
retry_after: Option<u64>,
rpm_limit: Option<u32>,
tpm_limit: Option<u32>,
current_usage: Option<f64>,
},
#[error("Quota exceeded for {provider}: {message}")]
QuotaExceeded {
provider: &'static str,
message: String,
},
#[error("Model '{model}' not found for {provider}")]
ModelNotFound {
provider: &'static str,
model: String,
},
#[error("Invalid request for {provider}: {message}")]
InvalidRequest {
provider: &'static str,
message: String,
},
#[error("Network error for {provider}: {message}")]
Network {
provider: &'static str,
message: String,
},
#[error("Provider {provider} is unavailable: {message}")]
ProviderUnavailable {
provider: &'static str,
message: String,
},
#[error("Feature '{feature}' not supported by {provider}")]
NotSupported {
provider: &'static str,
feature: String,
},
#[error("Feature '{feature}' not implemented for {provider}")]
NotImplemented {
provider: &'static str,
feature: String,
},
#[error("Configuration error for {provider}: {message}")]
Configuration {
provider: &'static str,
message: String,
},
#[error("Serialization error for {provider}: {message}")]
Serialization {
provider: &'static str,
message: String,
},
#[error("Timeout for {provider}: {message}")]
Timeout {
provider: &'static str,
message: String,
},
#[error("Context length exceeded for {provider}: max {max} tokens, got {actual} tokens")]
ContextLengthExceeded {
provider: &'static str,
max: usize,
actual: usize,
},
#[error("Content filtered by {provider} safety systems: {reason}")]
ContentFiltered {
provider: &'static str,
reason: String,
policy_violations: Option<Vec<String>>,
potentially_retryable: Option<bool>,
},
#[error("API error for {provider} (status {status}): {message}")]
ApiError {
provider: &'static str,
status: u16,
message: String,
},
#[error("Token limit exceeded for {provider}: {message}")]
TokenLimitExceeded {
provider: &'static str,
message: String,
},
#[error("Feature disabled for {provider}: {feature}")]
FeatureDisabled {
provider: &'static str,
feature: String,
},
#[error("Azure deployment error for {deployment}: {message}")]
DeploymentError {
provider: &'static str,
deployment: String,
message: String,
},
#[error("Failed to parse {provider} response: {message}")]
ResponseParsing {
provider: &'static str,
message: String,
},
#[error("Routing error from {provider}: tried {attempted_providers:?}, final error: {message}")]
RoutingError {
provider: &'static str,
attempted_providers: Vec<String>,
message: String,
},
#[error("Transformation error for {provider}: from {from_format} to {to_format}: {message}")]
TransformationError {
provider: &'static str,
from_format: String,
to_format: String,
message: String,
},
#[error("Operation cancelled for {provider}: {operation_type}")]
Cancelled {
provider: &'static str,
operation_type: String,
cancellation_reason: Option<String>,
},
#[error("Streaming error for {provider}: {stream_type} at position {position:?}")]
Streaming {
provider: &'static str,
stream_type: String,
position: Option<u64>,
last_chunk: Option<String>,
message: String,
},
#[error("{provider} error: {message}")]
Other {
provider: &'static str,
message: String,
},
}