Skip to main content

feagi_io/
error.rs

1use std::error::Error;
2use std::fmt::{Display, Formatter};
3
4#[derive(Debug, Clone, PartialEq)]
5pub enum FeagiNetworkError {
6    /// Failed to bind server socket to address
7    CannotBind(String),
8    /// Failed to unbind server socket from address
9    CannotUnbind(String),
10    /// Failed to connect client socket to server
11    CannotConnect(String),
12    /// Failed to disconnect client socket from server
13    CannotDisconnect(String),
14    /// Failed to send data
15    SendFailed(String),
16    /// Failed to receive data
17    ReceiveFailed(String),
18    /// Invalid socket properties (such as an invalid URL)
19    InvalidSocketProperties(String),
20    /// Socket creation failed
21    SocketCreationFailed(String),
22    /// General failure (e.g., configuration error, invalid state)
23    GeneralFailure(String),
24}
25
26impl Display for FeagiNetworkError {
27    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
28        match self {
29            FeagiNetworkError::CannotBind(msg) => {
30                write!(f, "FeagiNetworkError: Unable to bind: {}", msg)
31            }
32            FeagiNetworkError::CannotUnbind(msg) => {
33                write!(f, "FeagiNetworkError: Unable to unbind: {}", msg)
34            }
35            FeagiNetworkError::CannotConnect(msg) => {
36                write!(f, "FeagiNetworkError: Unable to connect: {}", msg)
37            }
38            FeagiNetworkError::CannotDisconnect(msg) => {
39                write!(f, "FeagiNetworkError: Unable to disconnect: {}", msg)
40            }
41            FeagiNetworkError::SendFailed(msg) => {
42                write!(f, "FeagiNetworkError: Send failed: {}", msg)
43            }
44            FeagiNetworkError::ReceiveFailed(msg) => {
45                write!(f, "FeagiNetworkError: Receive failed: {}", msg)
46            }
47            FeagiNetworkError::InvalidSocketProperties(msg) => {
48                write!(f, "FeagiNetworkError: Invalid socket properties: {}", msg)
49            }
50            FeagiNetworkError::SocketCreationFailed(msg) => {
51                write!(f, "FeagiNetworkError: Socket creation failed: {}", msg)
52            }
53            FeagiNetworkError::GeneralFailure(msg) => {
54                write!(f, "FeagiNetworkError: {}", msg)
55            }
56        }
57    }
58}
59
60impl Error for FeagiNetworkError {
61    fn source(&self) -> Option<&(dyn Error + 'static)> {
62        None
63    }
64}