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    /// Invalid path error
53    #[error("Invalid path: {0}")]
54    InvalidPath(String),
55
56    /// Generic error
57    #[error("{0}")]
58    Other(String),
59}
60
61impl From<redb::Error> for VectorDbError {
62    fn from(err: redb::Error) -> Self {
63        VectorDbError::Database(err.to_string())
64    }
65}
66
67impl From<redb::DatabaseError> for VectorDbError {
68    fn from(err: redb::DatabaseError) -> Self {
69        VectorDbError::Database(err.to_string())
70    }
71}
72
73impl From<redb::StorageError> for VectorDbError {
74    fn from(err: redb::StorageError) -> Self {
75        VectorDbError::Storage(err.to_string())
76    }
77}
78
79impl From<redb::TransactionError> for VectorDbError {
80    fn from(err: redb::TransactionError) -> Self {
81        VectorDbError::Database(err.to_string())
82    }
83}
84
85impl From<redb::TableError> for VectorDbError {
86    fn from(err: redb::TableError) -> Self {
87        VectorDbError::Database(err.to_string())
88    }
89}
90
91impl From<redb::CommitError> for VectorDbError {
92    fn from(err: redb::CommitError) -> Self {
93        VectorDbError::Database(err.to_string())
94    }
95}