rs2_stream/connectors/
connection_errors.rs1use std::fmt;
4
5#[derive(Debug, Clone, PartialEq)]
7pub enum ConnectorError {
8 ConnectionFailed(String),
10 AuthenticationFailed(String),
12 InvalidConfiguration(String),
14 SerializationError(String),
16 IO(String),
18 Timeout,
20 NotFound(String),
22 PermissionDenied(String),
24 ResourceExhausted,
26 ConnectorSpecific(String),
28 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) => write!(f, "Authentication failed: {}", msg),
37 ConnectorError::InvalidConfiguration(msg) => write!(f, "Invalid configuration: {}", msg),
38 ConnectorError::SerializationError(msg) => write!(f, "Serialization error: {}", msg),
39 ConnectorError::IO(msg) => write!(f, "I/O error: {}", msg),
40 ConnectorError::Timeout => write!(f, "Operation timed out"),
41 ConnectorError::NotFound(msg) => write!(f, "Resource not found: {}", msg),
42 ConnectorError::PermissionDenied(msg) => write!(f, "Permission denied: {}", msg),
43 ConnectorError::ResourceExhausted => write!(f, "Resource exhausted"),
44 ConnectorError::ConnectorSpecific(msg) => write!(f, "Connector error: {}", msg),
45 ConnectorError::Multiple(errors) => {
46 write!(f, "Multiple errors: ")?;
47 for (i, error) in errors.iter().enumerate() {
48 if i > 0 { write!(f, ", ")?; }
49 write!(f, "{}", error)?;
50 }
51 Ok(())
52 }
53 }
54 }
55}
56
57impl std::error::Error for ConnectorError {}
58
59impl From<std::io::Error> for ConnectorError {
60 fn from(err: std::io::Error) -> Self {
61 ConnectorError::IO(err.to_string())
62 }
63}
64
65impl From<serde_json::Error> for ConnectorError {
66 fn from(err: serde_json::Error) -> Self {
67 ConnectorError::SerializationError(err.to_string())
68 }
69}
70
71impl From<tokio::time::error::Elapsed> for ConnectorError {
72 fn from(_: tokio::time::error::Elapsed) -> Self {
73 ConnectorError::Timeout
74 }
75}
76
77pub type ConnectorResult<T> = Result<T, ConnectorError>;