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    /// v6.8.0:后端不可达(降级,进程不 panic)
25    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 {}