scirs2_cluster/
error.rs

1//! Error types for the clustering module
2
3use scirs2_core::error::CoreError;
4use scirs2_linalg::error::LinalgError;
5use thiserror::Error;
6
7/// Error type for clustering operations
8#[derive(Error, Debug)]
9pub enum ClusteringError {
10    /// Invalid input data
11    #[error("Invalid input: {0}")]
12    InvalidInput(String),
13
14    /// Computation error
15    #[error("Computation error: {0}")]
16    ComputationError(String),
17
18    /// Vector quantization specific errors
19    #[error("Vector quantization error: {0}")]
20    VqError(String),
21
22    /// Hierarchical clustering specific errors
23    #[error("Hierarchical clustering error: {0}")]
24    HierarchyError(String),
25
26    /// Empty cluster error
27    #[error("Empty cluster error: {0}")]
28    EmptyCluster(String),
29
30    /// Invalid state error
31    #[error("Invalid state: {0}")]
32    InvalidState(String),
33
34    /// Linear algebra error
35    #[error("Linear algebra error: {0}")]
36    LinalgError(#[from] LinalgError),
37
38    /// Core validation error
39    #[error("Core validation error: {0}")]
40    CoreError(#[from] CoreError),
41
42    /// I/O error
43    #[error("I/O error: {0}")]
44    IoError(#[from] std::io::Error),
45
46    /// JSON serialization error
47    #[error("JSON error: {0}")]
48    JsonError(#[from] serde_json::Error),
49
50    /// Other error
51    #[error("Error: {0}")]
52    Other(String),
53}
54
55/// Result type for clustering operations
56pub type Result<T> = std::result::Result<T, ClusteringError>;