nerve/integration/
error.rs

1//! System Integration Error Types
2//!
3//! Unified error handling for the integrated Nerve Framework system.
4
5use nerve_core_errors::NerveError;
6use std::fmt;
7
8/// Unified system error type that encompasses all component errors
9#[derive(Debug)]
10pub enum SystemError {
11    /// Memory system errors
12    Memory(String),
13    /// Thread system errors
14    Thread(String),
15    /// Node system errors
16    Node(String),
17    /// Communication system errors
18    Communication(String),
19    /// Integration-specific errors
20    Integration(String),
21    /// Performance monitoring errors
22    Performance(String),
23}
24
25impl fmt::Display for SystemError {
26    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27        match self {
28            SystemError::Memory(msg) => write!(f, "Memory error: {}", msg),
29            SystemError::Thread(msg) => write!(f, "Thread error: {}", msg),
30            SystemError::Node(msg) => write!(f, "Node error: {}", msg),
31            SystemError::Communication(msg) => write!(f, "Communication error: {}", msg),
32            SystemError::Integration(msg) => write!(f, "Integration error: {}", msg),
33            SystemError::Performance(msg) => write!(f, "Performance error: {}", msg),
34        }
35    }
36}
37
38impl std::error::Error for SystemError {}
39
40impl From<SystemError> for NerveError {
41    fn from(error: SystemError) -> Self {
42        match error {
43            SystemError::Memory(msg) => NerveError::Memory(msg),
44            SystemError::Thread(msg) => NerveError::Thread(msg),
45            SystemError::Node(msg) => NerveError::Node(msg),
46            SystemError::Communication(msg) => NerveError::Communication(msg),
47            SystemError::Integration(msg) => NerveError::Integration(msg),
48            SystemError::Performance(msg) => NerveError::Integration(msg), // Map performance to integration
49        }
50    }
51}
52
53/// Result type for system integration operations
54pub type SystemResult<T> = Result<T, SystemError>;
55
56/// Error conversion utilities
57impl SystemError {
58    /// Create a memory system error
59    pub fn memory<S: Into<String>>(msg: S) -> Self {
60        SystemError::Memory(msg.into())
61    }
62
63    /// Create a thread system error
64    pub fn thread<S: Into<String>>(msg: S) -> Self {
65        SystemError::Thread(msg.into())
66    }
67
68    /// Create a node system error
69    pub fn node<S: Into<String>>(msg: S) -> Self {
70        SystemError::Node(msg.into())
71    }
72
73    /// Create a communication system error
74    pub fn communication<S: Into<String>>(msg: S) -> Self {
75        SystemError::Communication(msg.into())
76    }
77
78    /// Create an integration error
79    pub fn integration<S: Into<String>>(msg: S) -> Self {
80        SystemError::Integration(msg.into())
81    }
82
83    /// Create a performance monitoring error
84    pub fn performance<S: Into<String>>(msg: S) -> Self {
85        SystemError::Performance(msg.into())
86    }
87}