Skip to content

Commit

Permalink
dns: derive Error for dns::Error
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwuelker committed Aug 11, 2024
1 parent 61dcf83 commit 9da8b75
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions crates/dns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ license.workspace = true
[dependencies]
sl-std = { workspace = true }
log = { workspace = true }
error-derive = { workspace = true }

[lints]
workspace = true
2 changes: 1 addition & 1 deletion crates/dns/src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl Domain {
nameserver = DNS_CACHE.get(&ns_domain)?;
} else {
// We did not make any progress
return Err(DNSError::CouldNotResolve(self.clone()));
return Err(DNSError::CouldNotResolve);
}
}
Err(DNSError::MaxResolutionStepsExceeded)
Expand Down
22 changes: 14 additions & 8 deletions crates/dns/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod resource_type;
use crate::resource_type::{ResourceRecord, ResourceRecordClass};
pub use dns_cache::DNS_CACHE;
pub use domain::Domain;
use error_derive::Error;

use std::{
io,
Expand All @@ -23,18 +24,23 @@ const MAX_RESOLUTION_STEPS: usize = 5;
/// See [this list of root servers](https://www.iana.org/domains/root/servers).
const ROOT_SERVER: IpAddr = IpAddr::V4(Ipv4Addr::new(199, 7, 83, 42));

#[derive(Debug)]
#[derive(Debug, Error)]
pub enum DNSError {
#[msg = "invalid response"]
InvalidResponse,
CouldNotResolve(Domain),

#[msg = "could not resolve"]
CouldNotResolve,

#[msg = "maximum number of resolution steps exceeded"]
MaxResolutionStepsExceeded,

#[msg = "unexpected id"]
UnexpectedID,

#[msg = "io error"]
IO(io::Error),
DomainTooLong,
}

impl From<io::Error> for DNSError {
fn from(value: io::Error) -> Self {
Self::IO(value)
}
#[msg = "domain too long"]
DomainTooLong,
}

0 comments on commit 9da8b75

Please sign in to comment.