From 71255eb265739c7fdb70486ab85533e1bebd1a49 Mon Sep 17 00:00:00 2001 From: Jonathan Woollett-Light Date: Mon, 16 Oct 2023 14:03:45 +0100 Subject: [PATCH] fix: Refactor error propagation Refactors error propagation to avoid logging and printing misleading error messages. Signed-off-by: Jonathan Woollett-Light --- src/firecracker/src/api_server_adapter.rs | 13 +++++++++---- src/firecracker/src/main.rs | 7 +++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/firecracker/src/api_server_adapter.rs b/src/firecracker/src/api_server_adapter.rs index 7a532463b86e..b2cad171f3c7 100644 --- a/src/firecracker/src/api_server_adapter.rs +++ b/src/firecracker/src/api_server_adapter.rs @@ -52,7 +52,7 @@ impl ApiServerAdapter { vm_resources: VmResources, vmm: Arc>, event_manager: &mut EventManager, - ) -> FcExitCode { + ) -> Result<(), FcExitCode> { let api_adapter = Arc::new(Mutex::new(Self { api_event_fd, from_api, @@ -64,10 +64,14 @@ impl ApiServerAdapter { event_manager .run() .expect("EventManager events driver fatal error"); - if let Some(exit_code) = vmm.lock().unwrap().shutdown_exit_code() { - return exit_code; + + match vmm.lock().unwrap().shutdown_exit_code() { + Some(FcExitCode::Ok) => break, + Some(exit_code) => return Err(exit_code), + None => continue, } } + Ok(()) } fn handle_request(&mut self, req_action: VmmAction) { @@ -245,7 +249,8 @@ pub(crate) fn run_with_api( api_thread.join().expect("Api thread should join"); match result { - Ok(exit_code) => Err(ApiServerError::MicroVMStoppedWithoutError(exit_code)), + Ok(Ok(())) => Ok(()), + Ok(Err(exit_code)) => Err(ApiServerError::MicroVMStoppedWithoutError(exit_code)), Err(exit_error) => Err(exit_error), } } diff --git a/src/firecracker/src/main.rs b/src/firecracker/src/main.rs index cf95ff1f9953..3e8964be4193 100644 --- a/src/firecracker/src/main.rs +++ b/src/firecracker/src/main.rs @@ -630,8 +630,11 @@ fn run_without_api( .run() .expect("Failed to start the event manager"); - if let Some(exit_code) = vmm.lock().unwrap().shutdown_exit_code() { - return Err(RunWithoutApiError::Shutdown(exit_code)); + match vmm.lock().unwrap().shutdown_exit_code() { + Some(FcExitCode::Ok) => break, + Some(exit_code) => return Err(RunWithoutApiError::Shutdown(exit_code)), + None => continue, } } + Ok(()) }