nerve/integration/
error.rs1use nerve_core_errors::NerveError;
6use std::fmt;
7
8#[derive(Debug)]
10pub enum SystemError {
11 Memory(String),
13 Thread(String),
15 Node(String),
17 Communication(String),
19 Integration(String),
21 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), }
50 }
51}
52
53pub type SystemResult<T> = Result<T, SystemError>;
55
56impl SystemError {
58 pub fn memory<S: Into<String>>(msg: S) -> Self {
60 SystemError::Memory(msg.into())
61 }
62
63 pub fn thread<S: Into<String>>(msg: S) -> Self {
65 SystemError::Thread(msg.into())
66 }
67
68 pub fn node<S: Into<String>>(msg: S) -> Self {
70 SystemError::Node(msg.into())
71 }
72
73 pub fn communication<S: Into<String>>(msg: S) -> Self {
75 SystemError::Communication(msg.into())
76 }
77
78 pub fn integration<S: Into<String>>(msg: S) -> Self {
80 SystemError::Integration(msg.into())
81 }
82
83 pub fn performance<S: Into<String>>(msg: S) -> Self {
85 SystemError::Performance(msg.into())
86 }
87}