use manifoldb_core::PointId;
use thiserror::Error;
use super::manager::CollectionError;
#[derive(Debug, Error)]
pub enum ApiError {
#[error(transparent)]
Collection(#[from] CollectionError),
#[error("point {point_id} not found in collection '{collection}'")]
PointNotFound {
point_id: PointId,
collection: String,
},
#[error("point {point_id} already exists in collection '{collection}'")]
PointAlreadyExists {
point_id: PointId,
collection: String,
},
#[error("vector '{vector_name}' dimension mismatch: expected {expected}, got {actual}")]
DimensionMismatch {
vector_name: String,
expected: usize,
actual: usize,
},
#[error("vector '{vector_name}' type mismatch: expected {expected}, got {actual}")]
VectorTypeMismatch {
vector_name: String,
expected: String,
actual: String,
},
#[error("vector '{vector_name}' not found in collection '{collection}'")]
VectorNotInSchema {
vector_name: String,
collection: String,
},
#[error("search query vector cannot be empty")]
EmptyQueryVector,
#[error("invalid filter: {0}")]
InvalidFilter(String),
#[error("storage error: {0}")]
Storage(String),
#[error("serialization error: {0}")]
Serialization(String),
#[error("collection '{0}' no longer exists")]
InvalidHandle(String),
#[error("search limit must be greater than zero")]
InvalidSearchLimit,
#[error("hybrid search requires at least two vector names")]
InsufficientVectorsForHybrid,
#[error("invalid state: {0}")]
InvalidState(String),
}
impl From<manifoldb_vector::error::VectorError> for ApiError {
fn from(err: manifoldb_vector::error::VectorError) -> Self {
Self::Storage(err.to_string())
}
}
pub type ApiResult<T> = std::result::Result<T, ApiError>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_display() {
let err = ApiError::PointNotFound {
point_id: PointId::new(42),
collection: "documents".to_string(),
};
assert!(err.to_string().contains("42"));
assert!(err.to_string().contains("documents"));
let err = ApiError::DimensionMismatch {
vector_name: "text".to_string(),
expected: 768,
actual: 384,
};
assert!(err.to_string().contains("768"));
assert!(err.to_string().contains("384"));
}
}