Skip to main content

optirs_nas/
error.rs

1//! Error types for OptiRS NAS module
2
3use std::error::Error;
4use std::fmt;
5
6/// Error type for NAS operations
7#[derive(Debug)]
8pub enum OptimError {
9    /// Invalid configuration
10    InvalidConfig(String),
11    /// Search space error
12    SearchSpaceError(String),
13    /// Evaluation error
14    EvaluationError(String),
15    /// Architecture encoding error
16    ArchitectureError(String),
17    /// Optimization error
18    OptimizationError(String),
19    /// Resource constraint violation
20    ResourceConstraintViolation(String),
21    /// Convergence failure
22    ConvergenceFailure(String),
23    /// Invalid parameter
24    InvalidParameter(String),
25    /// Configuration error
26    ConfigurationError(String),
27    /// Resource limit exceeded
28    ResourceLimitExceeded(String),
29    /// Requested functionality is not implemented
30    ///
31    /// Returned instead of silently substituting a fabricated result when a
32    /// code path has no real implementation available.
33    NotImplemented(String),
34}
35
36impl fmt::Display for OptimError {
37    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38        match self {
39            OptimError::InvalidConfig(msg) => write!(f, "Invalid configuration: {}", msg),
40            OptimError::SearchSpaceError(msg) => write!(f, "Search space error: {}", msg),
41            OptimError::EvaluationError(msg) => write!(f, "Evaluation error: {}", msg),
42            OptimError::ArchitectureError(msg) => write!(f, "Architecture error: {}", msg),
43            OptimError::OptimizationError(msg) => write!(f, "Optimization error: {}", msg),
44            OptimError::ResourceConstraintViolation(msg) => {
45                write!(f, "Resource constraint violation: {}", msg)
46            }
47            OptimError::ConvergenceFailure(msg) => write!(f, "Convergence failure: {}", msg),
48            OptimError::InvalidParameter(msg) => write!(f, "Invalid parameter: {}", msg),
49            OptimError::ConfigurationError(msg) => write!(f, "Configuration error: {}", msg),
50            OptimError::ResourceLimitExceeded(msg) => write!(f, "Resource limit exceeded: {}", msg),
51            OptimError::NotImplemented(msg) => write!(f, "Not implemented: {}", msg),
52        }
53    }
54}
55
56impl Error for OptimError {}
57
58/// Result type for NAS operations
59pub type Result<T> = std::result::Result<T, OptimError>;