aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-06-02 21:55:19 -0400
committerbnewbold <bnewbold@robocracy.org>2016-06-02 21:55:19 -0400
commit0b058f570e71a3eaa1314a947fdff3d88193a63f (patch)
tree0bcb7d79e68722c9a63501e6f2fe478aae9d37cf
parentc98d8a044308e3cde1de4945dbb7f5ee62ab52a5 (diff)
downloaducp-0b058f570e71a3eaa1314a947fdff3d88193a63f.tar.gz
ucp-0b058f570e71a3eaa1314a947fdff3d88193a63f.zip
more improvements to error handling
-rw-r--r--src/client.rs13
-rw-r--r--src/common.rs6
2 files changed, 11 insertions, 8 deletions
diff --git a/src/client.rs b/src/client.rs
index acc3425..f26c35d 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -39,15 +39,15 @@ pub fn run_client(host: &str, local_file: &str, remote_file: &str, remote_is_dir
let ssh_output = ssh_cmd.output().expect("couldn't get SSH sub-process output");
if !ssh_output.status.success() {
- println!("Error on remote end: {}", String::from_utf8_lossy(&ssh_output.stderr));
- exit(-1);
+ return Err(format!("Error on remote end: {}",
+ String::from_utf8_lossy(&ssh_output.stderr)));
}
let reply = String::from_utf8_lossy(&ssh_output.stdout);
- println!("SSH reply: {}", reply);
+ //println!("SSH reply: {}", reply);
let words: Vec<&str> = reply.split_whitespace().collect();
if words.len() != 7 || words[0] != "UCP" || words[1] != "CONNECT" {
- panic!("Unexpected data via SSH pipe (TCP)");
+ return Err("Unexpected data via SSH pipe (TCP)".to_string());
}
let remote_host = words[2];
let remote_port = words[3].parse::<u16>().expect("failed to parse remote port number");
@@ -64,7 +64,10 @@ pub fn run_client(host: &str, local_file: &str, remote_file: &str, remote_is_dir
let addr = net::IpAddr::from_str(remote_host).unwrap();
let mut socket = UdtSocket::new(udt::SocketFamily::AFInet, udt::SocketType::Stream).unwrap();
- socket.connect(net::SocketAddr::new(addr, remote_port)).unwrap();;
+ match socket.connect(net::SocketAddr::new(addr, remote_port)) {
+ Ok(_) => { println!("Connected."); },
+ Err(e) => { return Err(e.err_msg); },
+ };
let mut stream: UdtStream = UdtStream::new(socket);
if !no_crypto {
diff --git a/src/common.rs b/src/common.rs
index 77b28ce..9aa477f 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -31,7 +31,7 @@ pub fn source_files<S: Read + Write>(stream: &mut S, file_path: &str, recursive:
1 | 2 => { // Warning
unimplemented!();
},
- _ => { panic!("Unexpected status char!") },
+ _ => { return Err("Unexpected status char!".to_string()); },
};
let mut buf = [0; 4096];
@@ -52,7 +52,7 @@ pub fn source_files<S: Read + Write>(stream: &mut S, file_path: &str, recursive:
1 | 2 => { // Warning
unimplemented!();
},
- _ => { panic!("Unexpected status char!") },
+ _ => { return Err("Unexpected status char!".to_string()) },
};
Ok(())
}
@@ -89,7 +89,7 @@ pub fn sink_files<S: Read + Write>(stream: &mut S, file_path: &str, recursive: b
'D' => { unimplemented!(); },
'E' => { unimplemented!(); },
'T' => { unimplemented!(); },
- _ => { panic!(format!("Unexpected message type: {}", msg_type)); },
+ _ => { return Err(format!("Unexpected message type: {}", msg_type)); },
};
let line = raw_read_line(stream).unwrap();
println!("got msg: {}", line);