use thiserror::Error;
pub type Result<T> = std::result::Result<T, GnnError>;
#[derive(Error, Debug)]
pub enum GnnError {
#[error("Tensor dimension mismatch: expected {expected}, got {actual}")]
DimensionMismatch {
expected: String,
actual: String,
},
#[error("Invalid tensor shape: {0}")]
InvalidShape(String),
#[error("Layer configuration error: {0}")]
LayerConfig(String),
#[error("Training error: {0}")]
Training(String),
#[error("Compression error: {0}")]
Compression(String),
#[error("Search error: {0}")]
Search(String),
#[error("Invalid input: {0}")]
InvalidInput(String),
#[cfg(not(target_arch = "wasm32"))]
#[error("Memory mapping error: {0}")]
Mmap(String),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("Core error: {0}")]
Core(#[from] ruvector_core::error::RuvectorError),
#[error("{0}")]
Other(String),
}
impl GnnError {
pub fn dimension_mismatch(expected: impl Into<String>, actual: impl Into<String>) -> Self {
Self::DimensionMismatch {
expected: expected.into(),
actual: actual.into(),
}
}
pub fn invalid_shape(msg: impl Into<String>) -> Self {
Self::InvalidShape(msg.into())
}
pub fn layer_config(msg: impl Into<String>) -> Self {
Self::LayerConfig(msg.into())
}
pub fn training(msg: impl Into<String>) -> Self {
Self::Training(msg.into())
}
pub fn compression(msg: impl Into<String>) -> Self {
Self::Compression(msg.into())
}
pub fn search(msg: impl Into<String>) -> Self {
Self::Search(msg.into())
}
#[cfg(not(target_arch = "wasm32"))]
pub fn mmap(msg: impl Into<String>) -> Self {
Self::Mmap(msg.into())
}
pub fn invalid_input(msg: impl Into<String>) -> Self {
Self::InvalidInput(msg.into())
}
pub fn other(msg: impl Into<String>) -> Self {
Self::Other(msg.into())
}
}