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