ruvector_router_core/
error.rs

1//! Error types for the vector database
2
3use thiserror::Error;
4
5/// Result type alias for vector database operations
6pub type Result<T> = std::result::Result<T, VectorDbError>;
7
8/// Error types that can occur during vector database operations
9#[derive(Error, Debug)]
10pub enum VectorDbError {
11    /// IO error
12    #[error("IO error: {0}")]
13    Io(#[from] std::io::Error),
14
15    /// Storage error
16    #[error("Storage error: {0}")]
17    Storage(String),
18
19    /// Index error
20    #[error("Index error: {0}")]
21    Index(String),
22
23    /// Quantization error
24    #[error("Quantization error: {0}")]
25    Quantization(String),
26
27    /// Invalid dimensions
28    #[error("Invalid dimensions: expected {expected}, got {actual}")]
29    InvalidDimensions {
30        /// Expected dimensions
31        expected: usize,
32        /// Actual dimensions
33        actual: usize,
34    },
35
36    /// Vector not found
37    #[error("Vector not found: {0}")]
38    NotFound(String),
39
40    /// Invalid configuration
41    #[error("Invalid configuration: {0}")]
42    InvalidConfig(String),
43
44    /// Serialization error
45    #[error("Serialization error: {0}")]
46    Serialization(String),
47
48    /// Database error
49    #[error("Database error: {0}")]
50    Database(String),
51
52    /// Generic error
53    #[error("{0}")]
54    Other(String),
55}
56
57impl From<redb::Error> for VectorDbError {
58    fn from(err: redb::Error) -> Self {
59        VectorDbError::Database(err.to_string())
60    }
61}
62
63impl From<redb::DatabaseError> for VectorDbError {
64    fn from(err: redb::DatabaseError) -> Self {
65        VectorDbError::Database(err.to_string())
66    }
67}
68
69impl From<redb::StorageError> for VectorDbError {
70    fn from(err: redb::StorageError) -> Self {
71        VectorDbError::Storage(err.to_string())
72    }
73}
74
75impl From<redb::TransactionError> for VectorDbError {
76    fn from(err: redb::TransactionError) -> Self {
77        VectorDbError::Database(err.to_string())
78    }
79}
80
81impl From<redb::TableError> for VectorDbError {
82    fn from(err: redb::TableError) -> Self {
83        VectorDbError::Database(err.to_string())
84    }
85}
86
87impl From<redb::CommitError> for VectorDbError {
88    fn from(err: redb::CommitError) -> Self {
89        VectorDbError::Database(err.to_string())
90    }
91}