1
//! Errors coming from the DNS resolver
2

            
3
use hickory_net::NetError;
4
use thiserror::Error;
5
use tor_error::Bug;
6

            
7
/// An error representing a failed DNS lookup.
8
#[derive(Clone, Debug, Error)]
9
pub(crate) enum LookupError {
10
    /// The hostname from the RESOLVE message was not valid ASCII.
11
    #[error("Hostname is not ASCII")]
12
    NonAsciiHostname,
13

            
14
    /// An error coming from hickory
15
    #[error("failed to resolve name")]
16
    Hickory(#[from] NetError),
17

            
18
    /// An internal error
19
    #[error("internal error")]
20
    Bug(#[from] Bug),
21
}
22

            
23
impl LookupError {
24
    /// Whether this is a transient error
25
    pub(crate) fn is_transient(&self) -> bool {
26
        use LookupError as LE;
27

            
28
        match self {
29
            LE::Hickory(_) => {
30
                // TODO(relay): not all of these are transient!
31
                // We should see if the hickory folks would be happy with us
32
                // adding NetError::is_transient() method,
33
                // or, alternatively, just match on the inner error here
34
                true
35
            }
36
            LE::NonAsciiHostname | LE::Bug(_) => false,
37
        }
38
    }
39
}