scirs2_metrics/
error.rs

1//! Error types for the metrics module
2
3use thiserror::Error;
4
5/// Error type for metrics operations
6#[derive(Error, Debug)]
7pub enum MetricsError {
8    /// Invalid input data
9    #[error("Invalid input: {0}")]
10    InvalidInput(String),
11
12    /// Calculation error
13    #[error("Calculation error: {0}")]
14    CalculationError(String),
15
16    /// Computation error (used in parallel and streaming contexts)
17    #[error("Computation error: {0}")]
18    ComputationError(String),
19
20    /// Dimension mismatch between arrays
21    #[error("Dimension mismatch: {0}")]
22    DimensionMismatch(String),
23
24    /// Shape mismatch between arrays
25    #[error("Shape mismatch: shape1 = {shape1}, shape2 = {shape2}")]
26    ShapeMismatch {
27        /// First shape in mismatch
28        shape1: String,
29        /// Second shape in mismatch
30        shape2: String,
31    },
32
33    /// Invalid argument
34    #[error("Invalid argument: {0}")]
35    InvalidArgument(String),
36
37    /// Division by zero error
38    #[error("Division by zero")]
39    DivisionByZero,
40
41    /// Statistics error
42    #[error("Statistics error: {0}")]
43    StatsError(String),
44
45    /// Linear algebra error
46    #[error("Linear algebra error: {0}")]
47    LinalgError(String),
48
49    /// IO error
50    #[error("IO error: {0}")]
51    IOError(String),
52
53    /// Serialization error
54    #[error("Serialization error: {0}")]
55    SerializationError(String),
56
57    /// Deserialization error
58    #[error("Deserialization error: {0}")]
59    DeserializationError(String),
60
61    /// Visualization error
62    #[error("Visualization error: {0}")]
63    VisualizationError(String),
64
65    /// Memory allocation error
66    #[error("Memory error: {0}")]
67    MemoryError(String),
68
69    /// Index error
70    #[error("Index error: {0}")]
71    IndexError(String),
72
73    /// Core error
74    #[error("Core error: {0}")]
75    CoreError(#[from] scirs2_core::error::CoreError),
76
77    /// Consensus error
78    #[error("Consensus error: {0}")]
79    ConsensusError(String),
80
81    /// Sharding error
82    #[error("Sharding error: {0}")]
83    ShardingError(String),
84
85    /// Fault tolerance error
86    #[error("Fault tolerance error: {0}")]
87    FaultToleranceError(String),
88
89    /// Invalid operation
90    #[error("Invalid operation: {0}")]
91    InvalidOperation(String),
92
93    /// Other error
94    #[error("Error: {0}")]
95    Other(String),
96}
97
98/// Result type for metrics operations
99pub type Result<T> = std::result::Result<T, MetricsError>;