From f17cb6c969121d12937409f9ec0d204cad4a841c Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Thu, 18 Mar 2021 21:04:30 +0100 Subject: [PATCH] resolve domain to multiple addresses And warn instead of failling when a domain can't be resolved --- src/util/config.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/util/config.rs b/src/util/config.rs index 6b449459..9ff67711 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -90,14 +90,21 @@ where { use std::net::ToSocketAddrs; - let mut res = vec![]; - for s in >::deserialize(deserializer)? { - res.push( - s.to_socket_addrs() - .map_err(|_| de::Error::custom("could not resolve to a socket address"))? - .next() - .ok_or(de::Error::custom("could not resolve to a socket address"))?, - ); - } - Ok(res) + Ok(>::deserialize(deserializer)? + .iter() + .filter_map(|&name| { + name.to_socket_addrs() + .map(|iter| (name, iter)) + .map_err(|_| warn!("Error resolving \"{}\"", name)) + .ok() + }) + .map(|(name, iter)| { + let v = iter.collect::>(); + if v.is_empty() { + warn!("Error resolving \"{}\"", name) + } + v + }) + .flatten() + .collect()) }