Improved error-handling in config (fixes #98)

This commit is contained in:
Jokler 2017-10-17 00:38:59 +02:00
parent e3c93e72f2
commit 9ec7356d10
2 changed files with 6 additions and 8 deletions

View file

@ -119,7 +119,7 @@ impl Connection {
println!("Added {} to trusted certificates.", cert_path); println!("Added {} to trusted certificates.", cert_path);
} }
let connector = builder.build()?; 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| { .map_err(|e| {
let res: error::Error = e.into(); let res: error::Error = e.into();
res res
@ -134,7 +134,7 @@ impl Connection {
} else { } else {
Ok(ConnectionFuture::Unsecured( Ok(ConnectionFuture::Unsecured(
config, config,
TcpStream::connect(&config.socket_addr(), handle), TcpStream::connect(&config.socket_addr()?, handle),
)) ))
} }
} }

View file

@ -305,12 +305,10 @@ impl Config {
/// Gets the server and port as a `SocketAddr`. /// Gets the server and port as a `SocketAddr`.
/// This panics when server is not specified or the address is malformed. /// This panics when server is not specified or the address is malformed.
pub fn socket_addr(&self) -> SocketAddr { pub fn socket_addr(&self) -> Result<SocketAddr> {
format!("{}:{}", self.server(), self.port()) format!("{}:{}", self.server(), self.port()).to_socket_addrs()
.to_socket_addrs() .map(|mut i| i.next().unwrap())
.unwrap() .map_err(|e| e.into())
.next()
.unwrap()
} }
/// Gets the server password specified in the configuration. /// Gets the server password specified in the configuration.