Skip to main content

sz_orm_vector/
error.rs

1//! Vector 操作错误类型
2
3use std::fmt;
4
5/// Vector 操作错误
6#[derive(Debug)]
7pub enum VectorError {
8    /// Collection 不存在
9    CollectionNotFound(String),
10    /// 向量维度不匹配
11    DimensionMismatch { expected: usize, actual: usize },
12    /// 操作不支持(stub 模式)
13    Unsupported(String),
14    /// SQL 执行错误
15    Query(String),
16    /// 连接错误
17    Connection(String),
18    /// 配置错误
19    InvalidConfig(String),
20    /// 标识符校验失败
21    InvalidIdentifier(String),
22    /// M-16 修复:top_k 超过最大限制
23    TopKExceeded { requested: usize, max: usize },
24}
25
26impl fmt::Display for VectorError {
27    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28        match self {
29            VectorError::CollectionNotFound(name) => {
30                write!(f, "collection not found: {}", name)
31            }
32            VectorError::DimensionMismatch { expected, actual } => {
33                write!(
34                    f,
35                    "dimension mismatch: expected {}, got {}",
36                    expected, actual
37                )
38            }
39            VectorError::Unsupported(msg) => {
40                write!(f, "unsupported operation: {}", msg)
41            }
42            VectorError::Query(msg) => write!(f, "query error: {}", msg),
43            VectorError::Connection(msg) => write!(f, "connection error: {}", msg),
44            VectorError::InvalidConfig(msg) => write!(f, "invalid config: {}", msg),
45            VectorError::InvalidIdentifier(msg) => write!(f, "invalid identifier: {}", msg),
46            VectorError::TopKExceeded { requested, max } => {
47                write!(f, "top_k {} exceeds maximum allowed {}", requested, max)
48            }
49        }
50    }
51}
52
53impl std::error::Error for VectorError {}