vector/error.rs
1//! Error types for OpenData Vector operations.
2//!
3//! This module defines [`Error`], the primary error type for all vector
4//! operations, along with a convenient [`Result`] type alias.
5
6use common::serde::encoding::EncodingError;
7use common::{SequenceError, StorageError};
8
9/// Error type for OpenData Vector operations.
10///
11/// This enum captures all possible error conditions that can occur when
12/// interacting with the vector database, including storage failures, encoding
13/// issues, and invalid input.
14///
15/// # Error Categories
16///
17/// - [`Storage`](Error::Storage): Errors from the underlying SlateDB storage layer,
18/// such as I/O failures or corruption.
19/// - [`Encoding`](Error::Encoding): Errors during serialization or deserialization
20/// of vector data.
21/// - [`InvalidInput`](Error::InvalidInput): Errors caused by invalid parameters or
22/// arguments provided by the caller.
23/// - [`Internal`](Error::Internal): Unexpected internal errors that indicate bugs
24/// or invariant violations.
25#[derive(Debug, Clone, PartialEq, Eq)]
26pub enum Error {
27 /// Storage-related errors from the underlying SlateDB layer.
28 ///
29 /// These errors typically indicate I/O failures, corruption, or
30 /// issues with the object store backend.
31 Storage(String),
32
33 /// Encoding or decoding errors.
34 ///
35 /// These errors occur when serializing records for storage or
36 /// deserializing entries during reads.
37 Encoding(String),
38
39 /// Invalid input or parameter errors.
40 ///
41 /// These errors indicate that the caller provided invalid arguments,
42 /// such as bad dimensions, unknown fields, or malformed vectors.
43 InvalidInput(String),
44
45 /// Internal errors indicating bugs or invariant violations.
46 ///
47 /// These errors should not occur during normal operation and
48 /// typically indicate a bug in the implementation.
49 Internal(String),
50}
51
52impl std::error::Error for Error {}
53
54impl std::fmt::Display for Error {
55 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56 match self {
57 Error::Storage(msg) => write!(f, "Storage error: {}", msg),
58 Error::Encoding(msg) => write!(f, "Encoding error: {}", msg),
59 Error::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
60 Error::Internal(msg) => write!(f, "Internal error: {}", msg),
61 }
62 }
63}
64
65impl From<StorageError> for Error {
66 fn from(err: StorageError) -> Self {
67 match err {
68 StorageError::Storage(msg) => Error::Storage(msg),
69 StorageError::Internal(msg) => Error::Internal(msg),
70 }
71 }
72}
73
74impl From<SequenceError> for Error {
75 fn from(err: SequenceError) -> Self {
76 match err {
77 SequenceError::Storage(storage_err) => Error::from(storage_err),
78 SequenceError::Deserialize(de_err) => Error::Encoding(de_err.message),
79 }
80 }
81}
82
83impl From<EncodingError> for Error {
84 fn from(err: EncodingError) -> Self {
85 Error::Encoding(err.message)
86 }
87}
88
89impl From<&str> for Error {
90 fn from(msg: &str) -> Self {
91 Error::InvalidInput(msg.to_string())
92 }
93}
94
95/// Result type alias for OpenData Vector operations.
96///
97/// This is a convenience alias for `std::result::Result<T, Error>`.
98pub type Result<T> = std::result::Result<T, Error>;