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    /// Invalid dimension
33    #[error("Invalid dimension: {0}")]
34    InvalidDimension(String),
35
36    /// Storage error
37    #[error("Storage error: {0}")]
38    StorageError(String),
39
40    /// Model loading error
41    #[error("Model loading error: {0}")]
42    ModelLoadError(String),
43
44    /// Model inference error
45    #[error("Model inference error: {0}")]
46    ModelInferenceError(String),
47
48    /// Index error
49    #[error("Index error: {0}")]
50    IndexError(String),
51
52    /// Serialization error
53    #[error("Serialization error: {0}")]
54    SerializationError(String),
55
56    /// IO error
57    #[error("IO error: {0}")]
58    IoError(#[from] std::io::Error),
59
60    /// Database error
61    #[error("Database error: {0}")]
62    DatabaseError(String),
63
64    /// Invalid path error
65    #[error("Invalid path: {0}")]
66    InvalidPath(String),
67
68    /// Other errors
69    #[error("Internal error: {0}")]
70    Internal(String),
71}
72
73#[cfg(feature = "storage")]
74impl From<redb::Error> for RuvectorError {
75    fn from(err: redb::Error) -> Self {
76        RuvectorError::DatabaseError(err.to_string())
77    }
78}
79
80#[cfg(feature = "storage")]
81impl From<redb::DatabaseError> for RuvectorError {
82    fn from(err: redb::DatabaseError) -> Self {
83        RuvectorError::DatabaseError(err.to_string())
84    }
85}
86
87#[cfg(feature = "storage")]
88impl From<redb::StorageError> for RuvectorError {
89    fn from(err: redb::StorageError) -> Self {
90        RuvectorError::DatabaseError(err.to_string())
91    }
92}
93
94#[cfg(feature = "storage")]
95impl From<redb::TableError> for RuvectorError {
96    fn from(err: redb::TableError) -> Self {
97        RuvectorError::DatabaseError(err.to_string())
98    }
99}
100
101#[cfg(feature = "storage")]
102impl From<redb::TransactionError> for RuvectorError {
103    fn from(err: redb::TransactionError) -> Self {
104        RuvectorError::DatabaseError(err.to_string())
105    }
106}
107
108#[cfg(feature = "storage")]
109impl From<redb::CommitError> for RuvectorError {
110    fn from(err: redb::CommitError) -> Self {
111        RuvectorError::DatabaseError(err.to_string())
112    }
113}