Skip to main content

qail_qdrant/
error.rs

1//! Error types for Qdrant driver.
2
3use std::fmt;
4
5/// Result type for Qdrant operations.
6pub type QdrantResult<T> = Result<T, QdrantError>;
7
8/// Errors that can occur during Qdrant operations.
9#[derive(Debug)]
10pub enum QdrantError {
11    /// Connection failed.
12    Connection(String),
13    /// gRPC error.
14    Grpc(String),
15    /// Collection not found.
16    CollectionNotFound(String),
17    /// Point not found.
18    PointNotFound(String),
19    /// Invalid vector dimension.
20    DimensionMismatch {
21        /// Expected dimension from the collection config.
22        expected: usize,
23        /// Actual dimension of the provided vector.
24        got: usize,
25    },
26    /// Encoding error.
27    Encode(String),
28    /// Decode error.
29    Decode(String),
30    /// Timeout.
31    Timeout,
32}
33
34impl fmt::Display for QdrantError {
35    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36        match self {
37            QdrantError::Connection(msg) => write!(f, "Connection error: {}", msg),
38            QdrantError::Grpc(msg) => write!(f, "gRPC error: {}", msg),
39            QdrantError::CollectionNotFound(name) => write!(f, "Collection not found: {}", name),
40            QdrantError::PointNotFound(id) => write!(f, "Point not found: {}", id),
41            QdrantError::DimensionMismatch { expected, got } => {
42                write!(
43                    f,
44                    "Vector dimension mismatch: expected {}, got {}",
45                    expected, got
46                )
47            }
48            QdrantError::Encode(msg) => write!(f, "Encode error: {}", msg),
49            QdrantError::Decode(msg) => write!(f, "Decode error: {}", msg),
50            QdrantError::Timeout => write!(f, "Operation timed out"),
51        }
52    }
53}
54
55impl std::error::Error for QdrantError {}