fix exception if host isn't resolvable

This commit is contained in:
2022-10-26 16:25:37 +02:00
parent 09096d2769
commit ee1d6346ba

View File

@@ -25,14 +25,16 @@ fn upload_config(h: &Host) -> Result<String, String> {
let content = h.content.lock().unwrap(); let content = h.content.lock().unwrap();
let connection_string = format!("{}@{}", username, host); let connection_string = format!("{}@{}", username, host);
let addr: SocketAddr = format!("{}:{}", host, port) let addr: SocketAddr = match format!("{}:{}", host, port).to_socket_addrs() {
.to_socket_addrs() Ok(mut addrs) => addrs.nth(0).expect(format!("Invalid host/port in `{}:{}`", host, port).as_str()),
.unwrap().nth(0) _ => return Err(connection_string)
.expect(format!("Invalid host/port in `{}:{}`", host, port).as_str()); };
let tcp: TcpStream = match TcpStream::connect_timeout(&addr, Duration::from_secs(1)) {
let tcp: TcpStream = match TcpStream::connect_timeout(&addr, Duration::from_secs(3)) {
Ok(s) => s, Ok(s) => s,
Err(_) => return Err(connection_string) Err(_) => return Err(connection_string)
}; };
let mut sess = Session::new().unwrap(); let mut sess = Session::new().unwrap();
sess.set_tcp_stream(tcp); sess.set_tcp_stream(tcp);