From 6ece75a98946775c1ba6aed307e4586f43549249 Mon Sep 17 00:00:00 2001 From: sima Date: Mon, 23 Oct 2023 13:52:32 -0700 Subject: [PATCH] addressed comments --- src/service.rs | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/service.rs b/src/service.rs index c100708e..80f70143 100644 --- a/src/service.rs +++ b/src/service.rs @@ -72,7 +72,7 @@ pub fn start_services(settings: Settings) { .send(Err(ServiceError::TermSignal( "termination signal received".to_string(), ))) - .unwrap(); + .expect("failed to send message."); break; } _ => {} @@ -92,7 +92,7 @@ pub fn start_services(settings: Settings) { break; } Ok(_) => {} - Err(_) => error!("Failed to receive error message from thread"), + Err(_) => error!("failed to receive error message from thread"), } } @@ -137,16 +137,40 @@ impl Service { command.stdout(Stdio::piped()); command.stderr(Stdio::piped()); - let mut child = command.spawn().expect("Failed to execute command"); + let mut child = match command.spawn() { + Ok(x) => x, + Err(e) => { + sender + .send(Err(ServiceError::ThreadError(format!( + "failed to execute command: {}", + e + )))) + .expect("failed to send message."); + return; + } + }; let stdout = child.stdout.take().unwrap(); let stderr = child.stderr.take().unwrap(); let handles = start_log_handler(stdout, stderr, name_str); // Send the handles back to main thread - handle_sender.send(handles).unwrap(); + handle_sender + .send(handles) + .expect("failed to send message."); - let status = child.wait().expect("Failed to wait for command"); + let status = match child.wait() { + Ok(x) => x, + Err(e) => { + sender + .send(Err(ServiceError::ThreadError(format!( + "failed to wait for command: {}", + e + )))) + .expect("failed to send message."); + return; + } + }; if status.success() { sender.send(Ok(())).unwrap(); @@ -154,11 +178,12 @@ impl Service { let error_message = format!("Failed to start {} service.", name); sender .send(Err(ServiceError::ThreadError(error_message))) - .unwrap(); + .expect("failed to send message."); } }))); // Receive the handles from the channel and add them to the result vector - let received_handles: Vec>> = handle_receiver.recv().unwrap(); + let received_handles: Vec>> = + handle_receiver.recv().expect("failed to receive message."); result.extend(received_handles); result