rs2_stream/connectors/
connection_errors.rs

1//! Error types for connectors
2
3use std::fmt;
4
5/// Main error type for connector operations
6#[derive(Debug, Clone, PartialEq)]
7pub enum ConnectorError {
8    /// Connection failed
9    ConnectionFailed(String),
10    /// Authentication failed
11    AuthenticationFailed(String),
12    /// Invalid configuration
13    InvalidConfiguration(String),
14    /// Serialization/deserialization error
15    SerializationError(String),
16    /// I/O error
17    IO(String),
18    /// Timeout occurred
19    Timeout,
20    /// Resource not found
21    NotFound(String),
22    /// Permission denied
23    PermissionDenied(String),
24    /// Resource exhausted
25    ResourceExhausted,
26    /// Connector-specific error
27    ConnectorSpecific(String),
28    /// Multiple errors occurred
29    Multiple(Vec<ConnectorError>),
30}
31
32impl fmt::Display for ConnectorError {
33    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34        match self {
35            ConnectorError::ConnectionFailed(msg) => write!(f, "Connection failed: {}", msg),
36            ConnectorError::AuthenticationFailed(msg) => {
37                write!(f, "Authentication failed: {}", msg)
38            }
39            ConnectorError::InvalidConfiguration(msg) => {
40                write!(f, "Invalid configuration: {}", msg)
41            }
42            ConnectorError::SerializationError(msg) => write!(f, "Serialization error: {}", msg),
43            ConnectorError::IO(msg) => write!(f, "I/O error: {}", msg),
44            ConnectorError::Timeout => write!(f, "Operation timed out"),
45            ConnectorError::NotFound(msg) => write!(f, "Resource not found: {}", msg),
46            ConnectorError::PermissionDenied(msg) => write!(f, "Permission denied: {}", msg),
47            ConnectorError::ResourceExhausted => write!(f, "Resource exhausted"),
48            ConnectorError::ConnectorSpecific(msg) => write!(f, "Connector error: {}", msg),
49            ConnectorError::Multiple(errors) => {
50                write!(f, "Multiple errors: ")?;
51                for (i, error) in errors.iter().enumerate() {
52                    if i > 0 {
53                        write!(f, ", ")?;
54                    }
55                    write!(f, "{}", error)?;
56                }
57                Ok(())
58            }
59        }
60    }
61}
62
63impl std::error::Error for ConnectorError {}
64
65impl From<std::io::Error> for ConnectorError {
66    fn from(err: std::io::Error) -> Self {
67        ConnectorError::IO(err.to_string())
68    }
69}
70
71impl From<serde_json::Error> for ConnectorError {
72    fn from(err: serde_json::Error) -> Self {
73        ConnectorError::SerializationError(err.to_string())
74    }
75}
76
77impl From<tokio::time::error::Elapsed> for ConnectorError {
78    fn from(_: tokio::time::error::Elapsed) -> Self {
79        ConnectorError::Timeout
80    }
81}
82
83/// Result type for connector operations
84pub type ConnectorResult<T> = Result<T, ConnectorError>;