1use std::error::Error as StdError;
2use std::fmt::Debug;
3use std::net::AddrParseError;
4use std::str::Utf8Error;
5
6use thiserror::Error;
7
8#[cfg(feature = "dns-resolver")]
9use crate::dns;
10#[cfg(feature = "http-resolver")]
11use crate::http;
12
13#[derive(Debug, Error)]
15#[non_exhaustive]
16pub enum Error {
17 #[error("no or invalid IP address string found")]
19 Addr,
20 #[error("IP version not requested was returned")]
22 Version,
23 #[cfg(feature = "dns-resolver")]
25 #[cfg_attr(docsrs, doc(cfg(feature = "dns-resolver")))]
26 #[error("dns resolver: {0}")]
27 Dns(dns::Error),
28 #[cfg(feature = "http-resolver")]
30 #[cfg_attr(docsrs, doc(cfg(feature = "http-resolver")))]
31 #[error("http resolver: {0}")]
32 Http(http::Error),
33 #[error("other resolver: {0}")]
35 Other(Box<dyn StdError + Send + Sync + 'static>),
36}
37
38impl Error {
39 pub fn new<E>(error: E) -> Self
41 where
42 E: StdError + Send + Sync + 'static,
43 {
44 Self::Other(Box::new(error))
45 }
46}
47
48#[cfg(feature = "dns-resolver")]
49impl From<dns::Error> for Error {
50 fn from(error: dns::Error) -> Self {
51 Self::Dns(error)
52 }
53}
54
55#[cfg(feature = "http-resolver")]
56impl From<http::Error> for Error {
57 fn from(error: http::Error) -> Self {
58 Self::Http(error)
59 }
60}
61
62impl From<Utf8Error> for Error {
63 fn from(_: Utf8Error) -> Self {
64 Self::Addr
65 }
66}
67
68impl From<AddrParseError> for Error {
69 fn from(_: AddrParseError) -> Self {
70 Self::Addr
71 }
72}