ruvector_core/
error.rs

1//! Error types for Ruvector
2
3use thiserror::Error;
4
5/// Result type alias for Ruvector operations
6pub type Result<T> = std::result::Result<T, RuvectorError>;
7
8/// Main error type for Ruvector
9#[derive(Error, Debug)]
10pub enum RuvectorError {
11    /// Vector dimension mismatch
12    #[error("Dimension mismatch: expected {expected}, got {actual}")]
13    DimensionMismatch {
14        /// Expected dimension
15        expected: usize,
16        /// Actual dimension
17        actual: usize,
18    },
19
20    /// Vector not found
21    #[error("Vector not found: {0}")]
22    VectorNotFound(String),
23
24    /// Invalid parameter
25    #[error("Invalid parameter: {0}")]
26    InvalidParameter(String),
27
28    /// Invalid input
29    #[error("Invalid input: {0}")]
30    InvalidInput(String),
31
32    /// Storage error
33    #[error("Storage error: {0}")]
34    StorageError(String),
35
36    /// Index error
37    #[error("Index error: {0}")]
38    IndexError(String),
39
40    /// Serialization error
41    #[error("Serialization error: {0}")]
42    SerializationError(String),
43
44    /// IO error
45    #[error("IO error: {0}")]
46    IoError(#[from] std::io::Error),
47
48    /// Database error
49    #[error("Database error: {0}")]
50    DatabaseError(String),
51
52    /// Invalid path error
53    #[error("Invalid path: {0}")]
54    InvalidPath(String),
55
56    /// Other errors
57    #[error("Internal error: {0}")]
58    Internal(String),
59}
60
61#[cfg(feature = "storage")]
62impl From<redb::Error> for RuvectorError {
63    fn from(err: redb::Error) -> Self {
64        RuvectorError::DatabaseError(err.to_string())
65    }
66}
67
68#[cfg(feature = "storage")]
69impl From<redb::DatabaseError> for RuvectorError {
70    fn from(err: redb::DatabaseError) -> Self {
71        RuvectorError::DatabaseError(err.to_string())
72    }
73}
74
75#[cfg(feature = "storage")]
76impl From<redb::StorageError> for RuvectorError {
77    fn from(err: redb::StorageError) -> Self {
78        RuvectorError::DatabaseError(err.to_string())
79    }
80}
81
82#[cfg(feature = "storage")]
83impl From<redb::TableError> for RuvectorError {
84    fn from(err: redb::TableError) -> Self {
85        RuvectorError::DatabaseError(err.to_string())
86    }
87}
88
89#[cfg(feature = "storage")]
90impl From<redb::TransactionError> for RuvectorError {
91    fn from(err: redb::TransactionError) -> Self {
92        RuvectorError::DatabaseError(err.to_string())
93    }
94}
95
96#[cfg(feature = "storage")]
97impl From<redb::CommitError> for RuvectorError {
98    fn from(err: redb::CommitError) -> Self {
99        RuvectorError::DatabaseError(err.to_string())
100    }
101}