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) => {
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
83pub type ConnectorResult<T> = Result<T, ConnectorError>;