1//! StartTLS ServerConnector Error
2
3use hickory_resolver::{error::ResolveError, proto::error::ProtoError};
4#[cfg(feature = "tls-native")]
5use native_tls::Error as TlsError;
6use std::error::Error as StdError;
7use std::fmt;
8#[cfg(all(feature = "tls-rust", not(feature = "tls-native")))]
9use tokio_rustls::rustls::pki_types::InvalidDnsNameError;
10#[cfg(all(feature = "tls-rust", not(feature = "tls-native")))]
11use tokio_rustls::rustls::Error as TlsError;
12
13/// StartTLS ServerConnector Error
14#[derive(Debug)]
15pub enum Error {
16 /// Error resolving DNS and establishing a connection
17 Connection(ConnectorError),
18 /// DNS label conversion error, no details available from module
19 /// `idna`
20 Idna,
21 /// TLS error
22 Tls(TlsError),
23 #[cfg(all(feature = "tls-rust", not(feature = "tls-native")))]
24 /// DNS name parsing error
25 DnsNameError(InvalidDnsNameError),
26 /// tokio-xmpp error
27 TokioXMPP(crate::error::Error),
28}
29
30impl fmt::Display for Error {
31 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
32 match self {
33 Error::Connection(e) => write!(fmt, "connection error: {}", e),
34 Error::Idna => write!(fmt, "IDNA error"),
35 Error::Tls(e) => write!(fmt, "TLS error: {}", e),
36 #[cfg(all(feature = "tls-rust", not(feature = "tls-native")))]
37 Error::DnsNameError(e) => write!(fmt, "DNS name error: {}", e),
38 Error::TokioXMPP(e) => write!(fmt, "TokioXMPP error: {}", e),
39 }
40 }
41}
42
43impl StdError for Error {}
44
45impl From<crate::error::Error> for Error {
46 fn from(e: crate::error::Error) -> Self {
47 Error::TokioXMPP(e)
48 }
49}
50
51impl From<ConnectorError> for Error {
52 fn from(e: ConnectorError) -> Self {
53 Error::Connection(e)
54 }
55}
56
57impl From<TlsError> for Error {
58 fn from(e: TlsError) -> Self {
59 Error::Tls(e)
60 }
61}
62
63#[cfg(all(feature = "tls-rust", not(feature = "tls-native")))]
64impl From<InvalidDnsNameError> for Error {
65 fn from(e: InvalidDnsNameError) -> Self {
66 Error::DnsNameError(e)
67 }
68}
69
70/// Error establishing connection
71#[derive(Debug)]
72pub enum ConnectorError {
73 /// All attempts failed, no error available
74 AllFailed,
75 /// DNS protocol error
76 Dns(ProtoError),
77 /// DNS resolution error
78 Resolve(ResolveError),
79}
80
81impl StdError for ConnectorError {}
82
83impl std::fmt::Display for ConnectorError {
84 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
85 write!(fmt, "{:?}", self)
86 }
87}