1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, RuvectorError>;
7
8#[derive(Error, Debug)]
10pub enum RuvectorError {
11 #[error("Dimension mismatch: expected {expected}, got {actual}")]
13 DimensionMismatch {
14 expected: usize,
16 actual: usize,
18 },
19
20 #[error("Vector not found: {0}")]
22 VectorNotFound(String),
23
24 #[error("Invalid parameter: {0}")]
26 InvalidParameter(String),
27
28 #[error("Invalid input: {0}")]
30 InvalidInput(String),
31
32 #[error("Invalid dimension: {0}")]
34 InvalidDimension(String),
35
36 #[error("Storage error: {0}")]
38 StorageError(String),
39
40 #[error("Model loading error: {0}")]
42 ModelLoadError(String),
43
44 #[error("Model inference error: {0}")]
46 ModelInferenceError(String),
47
48 #[error("Index error: {0}")]
50 IndexError(String),
51
52 #[error("Serialization error: {0}")]
54 SerializationError(String),
55
56 #[error("IO error: {0}")]
58 IoError(#[from] std::io::Error),
59
60 #[error("Database error: {0}")]
62 DatabaseError(String),
63
64 #[error("Invalid path: {0}")]
66 InvalidPath(String),
67
68 #[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}