use thiserror::Error;
pub type Result<T> = std::result::Result<T, RuvectorError>;
#[derive(Error, Debug)]
pub enum RuvectorError {
#[error("Dimension mismatch: expected {expected}, got {actual}")]
DimensionMismatch {
expected: usize,
actual: usize,
},
#[error("Vector not found: {0}")]
VectorNotFound(String),
#[error("Invalid parameter: {0}")]
InvalidParameter(String),
#[error("Invalid input: {0}")]
InvalidInput(String),
#[error("Invalid dimension: {0}")]
InvalidDimension(String),
#[error("Storage error: {0}")]
StorageError(String),
#[error("Model loading error: {0}")]
ModelLoadError(String),
#[error("Model inference error: {0}")]
ModelInferenceError(String),
#[error("Index error: {0}")]
IndexError(String),
#[error("Serialization error: {0}")]
SerializationError(String),
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
#[error("Database error: {0}")]
DatabaseError(String),
#[error("Invalid path: {0}")]
InvalidPath(String),
#[error("Internal error: {0}")]
Internal(String),
}
#[cfg(feature = "storage")]
impl From<redb::Error> for RuvectorError {
fn from(err: redb::Error) -> Self {
RuvectorError::DatabaseError(err.to_string())
}
}
#[cfg(feature = "storage")]
impl From<redb::DatabaseError> for RuvectorError {
fn from(err: redb::DatabaseError) -> Self {
RuvectorError::DatabaseError(err.to_string())
}
}
#[cfg(feature = "storage")]
impl From<redb::StorageError> for RuvectorError {
fn from(err: redb::StorageError) -> Self {
RuvectorError::DatabaseError(err.to_string())
}
}
#[cfg(feature = "storage")]
impl From<redb::TableError> for RuvectorError {
fn from(err: redb::TableError) -> Self {
RuvectorError::DatabaseError(err.to_string())
}
}
#[cfg(feature = "storage")]
impl From<redb::TransactionError> for RuvectorError {
fn from(err: redb::TransactionError) -> Self {
RuvectorError::DatabaseError(err.to_string())
}
}
#[cfg(feature = "storage")]
impl From<redb::CommitError> for RuvectorError {
fn from(err: redb::CommitError) -> Self {
RuvectorError::DatabaseError(err.to_string())
}
}