2021-11-29 23:53:06 +00:00
|
|
|
use std::{error::Error, io};
|
2019-03-13 12:40:11 -07:00
|
|
|
|
2021-01-22 17:33:50 -08:00
|
|
|
use derive_more::Display;
|
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.
|
2021-01-22 17:33:50 -08:00
|
|
|
#[derive(Debug, Display)]
|
2019-03-13 12:40:11 -07:00
|
|
|
pub enum ConnectError {
|
|
|
|
/// Failed to resolve the hostname
|
2021-11-29 23:53:06 +00:00
|
|
|
#[display(fmt = "Failed resolving hostname")]
|
2021-01-22 17:33:50 -08:00
|
|
|
Resolver(Box<dyn std::error::Error>),
|
2019-03-13 12:40:11 -07:00
|
|
|
|
2021-11-29 23:53:06 +00:00
|
|
|
/// No DNS records
|
|
|
|
#[display(fmt = "No DNS records found for the input")]
|
2019-03-13 12:40:11 -07:00
|
|
|
NoRecords,
|
|
|
|
|
|
|
|
/// Invalid input
|
|
|
|
InvalidInput,
|
|
|
|
|
|
|
|
/// Unresolved host name
|
|
|
|
#[display(fmt = "Connector received `Connect` method with unresolved host")]
|
2020-05-03 23:14:22 +01:00
|
|
|
Unresolved,
|
2019-03-13 12:40:11 -07:00
|
|
|
|
2020-09-02 22:14:07 +01:00
|
|
|
/// Connection IO error
|
2019-03-13 12:40:11 -07:00
|
|
|
#[display(fmt = "{}", _0)]
|
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
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|