1use std::fmt;
4
5#[derive(Debug)]
7pub enum VectorError {
8 CollectionNotFound(String),
10 DimensionMismatch { expected: usize, actual: usize },
12 Unsupported(String),
14 Query(String),
16 Connection(String),
18 InvalidConfig(String),
20 InvalidIdentifier(String),
22 TopKExceeded { requested: usize, max: usize },
24 BackendUnreachable { reason: String },
26}
27
28impl fmt::Display for VectorError {
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 match self {
31 VectorError::CollectionNotFound(name) => {
32 write!(f, "collection not found: {}", name)
33 }
34 VectorError::DimensionMismatch { expected, actual } => {
35 write!(
36 f,
37 "dimension mismatch: expected {}, got {}",
38 expected, actual
39 )
40 }
41 VectorError::Unsupported(msg) => {
42 write!(f, "unsupported operation: {}", msg)
43 }
44 VectorError::Query(msg) => write!(f, "query error: {}", msg),
45 VectorError::Connection(msg) => write!(f, "connection error: {}", msg),
46 VectorError::InvalidConfig(msg) => write!(f, "invalid config: {}", msg),
47 VectorError::InvalidIdentifier(msg) => write!(f, "invalid identifier: {}", msg),
48 VectorError::TopKExceeded { requested, max } => {
49 write!(f, "top_k {} exceeds maximum allowed {}", requested, max)
50 }
51 VectorError::BackendUnreachable { reason } => {
52 write!(f, "backend unreachable: {}", reason)
53 }
54 }
55 }
56}
57
58impl std::error::Error for VectorError {}