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("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}