1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, GnnError>;
7
8#[derive(Error, Debug)]
10pub enum GnnError {
11 #[error("Tensor dimension mismatch: expected {expected}, got {actual}")]
13 DimensionMismatch {
14 expected: String,
16 actual: String,
18 },
19
20 #[error("Invalid tensor shape: {0}")]
22 InvalidShape(String),
23
24 #[error("Layer configuration error: {0}")]
26 LayerConfig(String),
27
28 #[error("Training error: {0}")]
30 Training(String),
31
32 #[error("Compression error: {0}")]
34 Compression(String),
35
36 #[error("Search error: {0}")]
38 Search(String),
39
40 #[error("Invalid input: {0}")]
42 InvalidInput(String),
43
44 #[cfg(not(target_arch = "wasm32"))]
46 #[error("Memory mapping error: {0}")]
47 Mmap(String),
48
49 #[error("I/O error: {0}")]
51 Io(#[from] std::io::Error),
52
53 #[error("Core error: {0}")]
55 Core(#[from] ruvector_core::error::RuvectorError),
56
57 #[error("{0}")]
59 Other(String),
60}
61
62impl GnnError {
63 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 pub fn invalid_shape(msg: impl Into<String>) -> Self {
73 Self::InvalidShape(msg.into())
74 }
75
76 pub fn layer_config(msg: impl Into<String>) -> Self {
78 Self::LayerConfig(msg.into())
79 }
80
81 pub fn training(msg: impl Into<String>) -> Self {
83 Self::Training(msg.into())
84 }
85
86 pub fn compression(msg: impl Into<String>) -> Self {
88 Self::Compression(msg.into())
89 }
90
91 pub fn search(msg: impl Into<String>) -> Self {
93 Self::Search(msg.into())
94 }
95
96 #[cfg(not(target_arch = "wasm32"))]
98 pub fn mmap(msg: impl Into<String>) -> Self {
99 Self::Mmap(msg.into())
100 }
101
102 pub fn invalid_input(msg: impl Into<String>) -> Self {
104 Self::InvalidInput(msg.into())
105 }
106
107 pub fn other(msg: impl Into<String>) -> Self {
109 Self::Other(msg.into())
110 }
111}