Skip to main content

optirs_learned/
error.rs

1//! Error handling for OptiRS Learned
2
3use thiserror::Error;
4
5/// Result type alias for OptiRS Learned operations
6pub type Result<T> = std::result::Result<T, OptimError>;
7
8/// Error types for OptiRS Learned operations
9#[derive(Error, Debug)]
10pub enum OptimError {
11    /// Insufficient data for the operation
12    #[error("Insufficient data: {0}")]
13    InsufficientData(String),
14
15    /// Analytics operation error
16    #[error("Analytics error: {0}")]
17    AnalyticsError(String),
18
19    /// Invalid state error
20    #[error("Invalid state: {0}")]
21    InvalidState(String),
22
23    /// Invalid configuration error
24    #[error("Invalid configuration: {0}")]
25    InvalidConfig(String),
26
27    /// Computation error
28    #[error("Computation error: {0}")]
29    ComputationError(String),
30
31    /// Network architecture error
32    #[error("Network architecture error: {0}")]
33    NetworkError(String),
34
35    /// Training error
36    #[error("Training error: {0}")]
37    TrainingError(String),
38
39    /// Serialization/deserialization error
40    #[error("Serialization error: {0}")]
41    SerializationError(String),
42
43    /// Generic error for other cases
44    #[error("Error: {0}")]
45    Other(String),
46}
47
48/// Convert from other error types
49impl From<serde_json::Error> for OptimError {
50    fn from(error: serde_json::Error) -> Self {
51        OptimError::SerializationError(error.to_string())
52    }
53}
54
55impl From<std::io::Error> for OptimError {
56    fn from(error: std::io::Error) -> Self {
57        OptimError::Other(error.to_string())
58    }
59}