From 5cc61e8d2140280421b5962b2911ebbcc927e9d1 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Fri, 26 Mar 2021 01:15:55 +0100 Subject: re-add error checking --- mumctl/src/main.rs | 10 +++++----- mumd/src/main.rs | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 3cbbcf7..123f5cd 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -615,15 +615,15 @@ fn parse_status(server_state: &mumlib::state::Server) { } fn send_command(command: Command) -> Result>, crate::Error> { - let mut connection = UnixStream::connect("/tmp/mumd").unwrap(); + let mut connection = UnixStream::connect("/tmp/mumd").map_err(|_| Error::ConnectionError)?; let serialized = bincode::serialize(&command).unwrap(); - connection.write(&(serialized.len() as u32).to_be_bytes()).unwrap(); - connection.write(&serialized).unwrap(); + connection.write(&(serialized.len() as u32).to_be_bytes()).map_err(|_| Error::ConnectionError)?; + connection.write(&serialized).map_err(|_| Error::ConnectionError)?; - connection.read_exact(&mut [0; 4]).unwrap(); - let response = bincode::deserialize_from(&mut connection).unwrap(); + connection.read_exact(&mut [0; 4]).map_err(|_| Error::ConnectionError)?; + let response = bincode::deserialize_from(&mut connection).map_err(|_| Error::ConnectionError)?; Ok(response) } diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 5b22089..18b84b8 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -77,7 +77,8 @@ async fn receive_commands( reader.filter_map(|buf| async { buf.ok() }) - .map(|buf| bincode::deserialize::(&buf).unwrap()) + .map(|buf| bincode::deserialize::(&buf)) + .filter_map(|e| async { e.ok() }) .filter_map(|command| async { let (tx, rx) = oneshot::channel(); -- cgit v1.2.1