From 9ec7356d1065eb93a446493b7ac7ffb3f81beac2 Mon Sep 17 00:00:00 2001 From: Jokler Date: Tue, 17 Oct 2017 00:38:59 +0200 Subject: [PATCH] Improved error-handling in config (fixes #98) --- src/client/conn.rs | 4 ++-- src/client/data/config.rs | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/client/conn.rs b/src/client/conn.rs index 49ad4b3..bb2848d 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -119,7 +119,7 @@ impl Connection { println!("Added {} to trusted certificates.", cert_path); } let connector = builder.build()?; - let stream = Box::new(TcpStream::connect(&config.socket_addr(), handle) + let stream = Box::new(TcpStream::connect(&config.socket_addr()?, handle) .map_err(|e| { let res: error::Error = e.into(); res @@ -134,7 +134,7 @@ impl Connection { } else { Ok(ConnectionFuture::Unsecured( config, - TcpStream::connect(&config.socket_addr(), handle), + TcpStream::connect(&config.socket_addr()?, handle), )) } } diff --git a/src/client/data/config.rs b/src/client/data/config.rs index 71506ae..b2aaa92 100644 --- a/src/client/data/config.rs +++ b/src/client/data/config.rs @@ -305,12 +305,10 @@ impl Config { /// Gets the server and port as a `SocketAddr`. /// This panics when server is not specified or the address is malformed. - pub fn socket_addr(&self) -> SocketAddr { - format!("{}:{}", self.server(), self.port()) - .to_socket_addrs() - .unwrap() - .next() - .unwrap() + pub fn socket_addr(&self) -> Result { + format!("{}:{}", self.server(), self.port()).to_socket_addrs() + .map(|mut i| i.next().unwrap()) + .map_err(|e| e.into()) } /// Gets the server password specified in the configuration.