ruvector_gnn/
error.rs

1//! Error types for the GNN module.
2
3use thiserror::Error;
4
5/// Result type alias for GNN operations.
6pub type Result<T> = std::result::Result<T, GnnError>;
7
8/// Errors that can occur during GNN operations.
9#[derive(Error, Debug)]
10pub enum GnnError {
11    /// Tensor dimension mismatch
12    #[error("Tensor dimension mismatch: expected {expected}, got {actual}")]
13    DimensionMismatch {
14        /// Expected dimension
15        expected: String,
16        /// Actual dimension
17        actual: String,
18    },
19
20    /// Invalid tensor shape
21    #[error("Invalid tensor shape: {0}")]
22    InvalidShape(String),
23
24    /// Layer configuration error
25    #[error("Layer configuration error: {0}")]
26    LayerConfig(String),
27
28    /// Training error
29    #[error("Training error: {0}")]
30    Training(String),
31
32    /// Compression error
33    #[error("Compression error: {0}")]
34    Compression(String),
35
36    /// Search error
37    #[error("Search error: {0}")]
38    Search(String),
39
40    /// Invalid input
41    #[error("Invalid input: {0}")]
42    InvalidInput(String),
43
44    /// Memory mapping error
45    #[cfg(not(target_arch = "wasm32"))]
46    #[error("Memory mapping error: {0}")]
47    Mmap(String),
48
49    /// I/O error
50    #[error("I/O error: {0}")]
51    Io(#[from] std::io::Error),
52
53    /// Core library error
54    #[error("Core error: {0}")]
55    Core(#[from] ruvector_core::error::RuvectorError),
56
57    /// Generic error
58    #[error("{0}")]
59    Other(String),
60}
61
62impl GnnError {
63    /// Create a dimension mismatch error
64    pub fn dimension_mismatch(expected: impl Into<String>, actual: impl Into<String>) -> Self {
65        Self::DimensionMismatch {
66            expected: expected.into(),
67            actual: actual.into(),
68        }
69    }
70
71    /// Create an invalid shape error
72    pub fn invalid_shape(msg: impl Into<String>) -> Self {
73        Self::InvalidShape(msg.into())
74    }
75
76    /// Create a layer config error
77    pub fn layer_config(msg: impl Into<String>) -> Self {
78        Self::LayerConfig(msg.into())
79    }
80
81    /// Create a training error
82    pub fn training(msg: impl Into<String>) -> Self {
83        Self::Training(msg.into())
84    }
85
86    /// Create a compression error
87    pub fn compression(msg: impl Into<String>) -> Self {
88        Self::Compression(msg.into())
89    }
90
91    /// Create a search error
92    pub fn search(msg: impl Into<String>) -> Self {
93        Self::Search(msg.into())
94    }
95
96    /// Create a memory mapping error
97    #[cfg(not(target_arch = "wasm32"))]
98    pub fn mmap(msg: impl Into<String>) -> Self {
99        Self::Mmap(msg.into())
100    }
101
102    /// Create an invalid input error
103    pub fn invalid_input(msg: impl Into<String>) -> Self {
104        Self::InvalidInput(msg.into())
105    }
106
107    /// Create a generic error
108    pub fn other(msg: impl Into<String>) -> Self {
109        Self::Other(msg.into())
110    }
111}