aimds_response/
error.rs

1//! Error types for AIMDS response layer
2
3use thiserror::Error;
4
5/// Result type for response operations
6pub type Result<T> = std::result::Result<T, ResponseError>;
7
8/// Errors that can occur in the response system
9#[derive(Error, Debug)]
10pub enum ResponseError {
11    #[error("Meta-learning error: {0}")]
12    MetaLearning(String),
13
14    #[error("Mitigation failed: {0}")]
15    MitigationFailed(String),
16
17    #[error("Strategy not found: {0}")]
18    StrategyNotFound(String),
19
20    #[error("Rollback failed: {0}")]
21    RollbackFailed(String),
22
23    #[error("Audit logging error: {0}")]
24    AuditError(String),
25
26    #[error("Invalid configuration: {0}")]
27    InvalidConfiguration(String),
28
29    #[error("Resource unavailable: {0}")]
30    ResourceUnavailable(String),
31
32    #[error("Timeout during {operation}: {details}")]
33    Timeout {
34        operation: String,
35        details: String,
36    },
37
38    #[error("Strange-loop error: {0}")]
39    StrangeLoopError(#[from] midstreamer_strange_loop::StrangeLoopError),
40
41    #[error("AIMDS core error: {0}")]
42    CoreError(#[from] aimds_core::AimdsError),
43
44    #[error("IO error: {0}")]
45    Io(#[from] std::io::Error),
46
47    #[error("Serialization error: {0}")]
48    Serialization(#[from] serde_json::Error),
49
50    #[error("Other error: {0}")]
51    Other(#[from] anyhow::Error),
52}
53
54impl ResponseError {
55    /// Check if error is retryable
56    pub fn is_retryable(&self) -> bool {
57        matches!(
58            self,
59            ResponseError::Timeout { .. }
60                | ResponseError::ResourceUnavailable(_)
61        )
62    }
63
64    /// Get error severity level
65    pub fn severity(&self) -> ErrorSeverity {
66        match self {
67            ResponseError::MitigationFailed(_) => ErrorSeverity::Critical,
68            ResponseError::RollbackFailed(_) => ErrorSeverity::Critical,
69            ResponseError::MetaLearning(_) => ErrorSeverity::Warning,
70            ResponseError::Timeout { .. } => ErrorSeverity::Warning,
71            _ => ErrorSeverity::Error,
72        }
73    }
74}
75
76/// Error severity levels
77#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
78pub enum ErrorSeverity {
79    Critical,
80    Error,
81    Warning,
82    Info,
83}