ruvector_collections/
error.rs

1//! Error types for collection management
2
3use thiserror::Error;
4
5/// Result type for collection operations
6pub type Result<T> = std::result::Result<T, CollectionError>;
7
8/// Errors that can occur during collection management
9#[derive(Debug, Error)]
10pub enum CollectionError {
11    /// Collection was not found
12    #[error("Collection not found: {name}")]
13    CollectionNotFound {
14        /// Name of the missing collection
15        name: String,
16    },
17
18    /// Collection already exists
19    #[error("Collection already exists: {name}")]
20    CollectionAlreadyExists {
21        /// Name of the existing collection
22        name: String,
23    },
24
25    /// Alias was not found
26    #[error("Alias not found: {alias}")]
27    AliasNotFound {
28        /// Name of the missing alias
29        alias: String,
30    },
31
32    /// Alias already exists
33    #[error("Alias already exists: {alias}")]
34    AliasAlreadyExists {
35        /// Name of the existing alias
36        alias: String,
37    },
38
39    /// Invalid collection configuration
40    #[error("Invalid configuration: {message}")]
41    InvalidConfiguration {
42        /// Error message
43        message: String,
44    },
45
46    /// Alias points to non-existent collection
47    #[error("Alias '{alias}' points to non-existent collection '{collection}'")]
48    InvalidAlias {
49        /// Alias name
50        alias: String,
51        /// Target collection name
52        collection: String,
53    },
54
55    /// Cannot delete collection with active aliases
56    #[error("Cannot delete collection '{collection}' because it has active aliases: {aliases:?}")]
57    CollectionHasAliases {
58        /// Collection name
59        collection: String,
60        /// List of aliases
61        aliases: Vec<String>,
62    },
63
64    /// Invalid collection name
65    #[error("Invalid collection name: {name} - {reason}")]
66    InvalidName {
67        /// Collection name
68        name: String,
69        /// Reason for invalidity
70        reason: String,
71    },
72
73    /// Core database error
74    #[error("Database error: {0}")]
75    DatabaseError(#[from] ruvector_core::error::RuvectorError),
76
77    /// IO error
78    #[error("IO error: {0}")]
79    IoError(#[from] std::io::Error),
80
81    /// Serialization error
82    #[error("Serialization error: {0}")]
83    SerializationError(String),
84}
85
86impl From<serde_json::Error> for CollectionError {
87    fn from(err: serde_json::Error) -> Self {
88        CollectionError::SerializationError(err.to_string())
89    }
90}
91
92impl From<bincode::error::EncodeError> for CollectionError {
93    fn from(err: bincode::error::EncodeError) -> Self {
94        CollectionError::SerializationError(err.to_string())
95    }
96}
97
98impl From<bincode::error::DecodeError> for CollectionError {
99    fn from(err: bincode::error::DecodeError) -> Self {
100        CollectionError::SerializationError(err.to_string())
101    }
102}