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);
}
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),
))
}
}

View file

@ -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<SocketAddr> {
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.