2022-01-28 17:09:33 -05:00
|
|
|
use std::{error::Error, fmt, io};
|
2019-03-13 12:40:11 -07:00
|
|
|
|
2021-11-29 23:53:06 +00:00
|
|
|
/// Errors that can result from using a connector service.
|
2022-01-28 17:09:33 -05:00
|
|
|
#[derive(Debug)]
|
2019-03-13 12:40:11 -07:00
|
|
|
pub enum ConnectError {
|
2022-01-28 17:09:33 -05:00
|
|
|
/// Failed to resolve the hostname.
|
2021-01-22 17:33:50 -08:00
|
|
|
Resolver(Box<dyn std::error::Error>),
|
2019-03-13 12:40:11 -07:00
|
|
|
|
2022-01-28 17:09:33 -05:00
|
|
|
/// No DNS records.
|
2019-03-13 12:40:11 -07:00
|
|
|
NoRecords,
|
|
|
|
|
2022-01-28 17:09:33 -05:00
|
|
|
/// Invalid input.
|
2019-03-13 12:40:11 -07:00
|
|
|
InvalidInput,
|
|
|
|
|
2022-01-28 17:09:33 -05:00
|
|
|
/// Unresolved host name.
|
2020-05-03 23:14:22 +01:00
|
|
|
Unresolved,
|
2019-03-13 12:40:11 -07:00
|
|
|
|
2022-01-28 17:09:33 -05:00
|
|
|
/// Connection IO error.
|
2019-03-13 14:38:33 -07:00
|
|
|
Io(io::Error),
|
2019-03-13 12:40:11 -07:00
|
|
|
}
|
2021-11-29 23:53:06 +00:00
|
|
|
|
2022-01-28 17:09:33 -05:00
|
|
|
impl fmt::Display for ConnectError {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
match self {
|
|
|
|
Self::NoRecords => f.write_str("No DNS records found for the input"),
|
|
|
|
Self::InvalidInput => f.write_str("Invalid input"),
|
|
|
|
Self::Unresolved => {
|
|
|
|
f.write_str("Connector received `Connect` method with unresolved host")
|
|
|
|
}
|
|
|
|
Self::Resolver(_) => f.write_str("Failed to resolve hostname"),
|
|
|
|
Self::Io(_) => f.write_str("I/O error"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-29 23:53:06 +00:00
|
|
|
impl Error for ConnectError {
|
|
|
|
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
|
|
|
match self {
|
|
|
|
Self::Resolver(err) => Some(&**err),
|
|
|
|
Self::Io(err) => Some(err),
|
|
|
|
Self::NoRecords | Self::InvalidInput | Self::Unresolved => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|