use crate::storage::persistent::types::StorageDriverError;
use crate::storage::StorageError;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum IndexError {
#[error("Index '{0}' already exists")]
AlreadyExists(String),
#[error("Index '{0}' not found")]
NotFound(String),
#[error("Invalid index configuration: {0}")]
InvalidConfiguration(String),
#[error("Dimension mismatch: expected {expected}, got {got}")]
DimensionMismatch { expected: usize, got: usize },
#[error("Serialization error: {0}")]
SerializationError(#[from] bincode::Error),
#[error("Storage error: {0}")]
StorageError(#[from] StorageError),
#[error("Storage driver error: {0}")]
StorageDriverError(#[from] StorageDriverError),
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
#[error("Query error: {0}")]
QueryError(String),
#[error("Index is not ready for operations")]
NotReady,
#[error("Operation not supported by this index type")]
UnsupportedOperation,
#[error("Index maintenance failed: {0}")]
MaintenanceError(String),
#[error("Concurrent modification error")]
ConcurrentModification,
#[error("Index corruption detected: {0}")]
CorruptionError(String),
}
impl IndexError {
pub fn query<S: Into<String>>(msg: S) -> Self {
Self::QueryError(msg.into())
}
pub fn config<S: Into<String>>(msg: S) -> Self {
Self::InvalidConfiguration(msg.into())
}
pub fn maintenance<S: Into<String>>(msg: S) -> Self {
Self::MaintenanceError(msg.into())
}
pub fn io<S: Into<String>>(msg: S) -> Self {
Self::IoError(std::io::Error::new(std::io::ErrorKind::Other, msg.into()))
}
pub fn creation<S: Into<String>>(msg: S) -> Self {
Self::InvalidConfiguration(msg.into())
}
pub fn serialization<S: Into<String>>(msg: S) -> Self {
Self::IoError(std::io::Error::new(
std::io::ErrorKind::InvalidData,
msg.into(),
))
}
pub fn deserialization<S: Into<String>>(msg: S) -> Self {
Self::IoError(std::io::Error::new(
std::io::ErrorKind::InvalidData,
msg.into(),
))
}
}