77 lines
1.9 KiB
Rust
77 lines
1.9 KiB
Rust
|
|
use thiserror::Error;
|
||
|
|
|
||
|
|
#[derive(Error, Debug)]
|
||
|
|
pub enum EmbeddingError {
|
||
|
|
#[error("Provider initialization failed: {0}")]
|
||
|
|
Initialization(String),
|
||
|
|
|
||
|
|
#[error("Provider not available: {0}")]
|
||
|
|
ProviderUnavailable(String),
|
||
|
|
|
||
|
|
#[error("API request failed: {0}")]
|
||
|
|
ApiError(String),
|
||
|
|
|
||
|
|
#[error("Invalid input: {0}")]
|
||
|
|
InvalidInput(String),
|
||
|
|
|
||
|
|
#[error("Dimension mismatch: expected {expected}, got {actual}")]
|
||
|
|
DimensionMismatch { expected: usize, actual: usize },
|
||
|
|
|
||
|
|
#[error("Batch size {size} exceeds maximum {max}")]
|
||
|
|
BatchSizeExceeded { size: usize, max: usize },
|
||
|
|
|
||
|
|
#[error("Cache error: {0}")]
|
||
|
|
CacheError(String),
|
||
|
|
|
||
|
|
#[error("Store error: {0}")]
|
||
|
|
StoreError(String),
|
||
|
|
|
||
|
|
#[error("Serialization error: {0}")]
|
||
|
|
SerializationError(String),
|
||
|
|
|
||
|
|
#[error("Rate limit exceeded: {0}")]
|
||
|
|
RateLimitExceeded(String),
|
||
|
|
|
||
|
|
#[error("Timeout: {0}")]
|
||
|
|
Timeout(String),
|
||
|
|
|
||
|
|
#[error("Configuration error: {0}")]
|
||
|
|
ConfigError(String),
|
||
|
|
|
||
|
|
#[error("IO error: {0}")]
|
||
|
|
IoError(String),
|
||
|
|
|
||
|
|
#[error("HTTP error: {0}")]
|
||
|
|
HttpError(String),
|
||
|
|
|
||
|
|
#[error(transparent)]
|
||
|
|
Other(#[from] Box<dyn std::error::Error + Send + Sync>),
|
||
|
|
}
|
||
|
|
|
||
|
|
impl From<std::io::Error> for EmbeddingError {
|
||
|
|
fn from(err: std::io::Error) -> Self {
|
||
|
|
Self::IoError(err.to_string())
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl From<serde_json::Error> for EmbeddingError {
|
||
|
|
fn from(err: serde_json::Error) -> Self {
|
||
|
|
Self::SerializationError(err.to_string())
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[cfg(feature = "reqwest")]
|
||
|
|
impl From<reqwest::Error> for EmbeddingError {
|
||
|
|
fn from(err: reqwest::Error) -> Self {
|
||
|
|
if err.is_timeout() {
|
||
|
|
Self::Timeout(err.to_string())
|
||
|
|
} else if err.is_status() {
|
||
|
|
Self::HttpError(format!("HTTP {}: {}", err.status().unwrap(), err))
|
||
|
|
} else {
|
||
|
|
Self::ApiError(err.to_string())
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
pub type Result<T> = std::result::Result<T, EmbeddingError>;
|