From bc9bef6ec16b9c852134b1f3f54f53ed49114a86 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Thu, 31 Oct 2019 14:56:45 -0700 Subject: [PATCH] Handle resolution errors at startup --- lib/src/lightclient.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/src/lightclient.rs b/lib/src/lightclient.rs index 823720d..1fd62a1 100644 --- a/lib/src/lightclient.rs +++ b/lib/src/lightclient.rs @@ -75,6 +75,13 @@ impl LightClientConfig { } pub fn create(server: http::Uri, dangerous: bool) -> io::Result<(LightClientConfig, u64)> { + use std::net::ToSocketAddrs; + // Test for a connection first + format!("{}:{}", server.host().unwrap(), server.port_part().unwrap()) + .to_socket_addrs()? + .next() + .ok_or(std::io::Error::new(ErrorKind::ConnectionRefused, "Couldn't resolve server!"))?; + // Do a getinfo first, before opening the wallet let info = grpcconnector::get_info(server.clone(), dangerous) .map_err(|e| std::io::Error::new(ErrorKind::ConnectionRefused, e))?;