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("Storage error: {0}")]
34 StorageError(String),
35
36 #[error("Index error: {0}")]
38 IndexError(String),
39
40 #[error("Serialization error: {0}")]
42 SerializationError(String),
43
44 #[error("IO error: {0}")]
46 IoError(#[from] std::io::Error),
47
48 #[error("Database error: {0}")]
50 DatabaseError(String),
51
52 #[error("Invalid path: {0}")]
54 InvalidPath(String),
55
56 #[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}