From 41c124ed88eff94986edd465c41f985f62bcbe28 Mon Sep 17 00:00:00 2001 From: duong Date: Wed, 23 Oct 2024 22:12:23 +0700 Subject: [PATCH] download_handler: add error handling for multiple executable install --- src/cli/download_handler.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/cli/download_handler.rs b/src/cli/download_handler.rs index d7b609c..72905e7 100644 --- a/src/cli/download_handler.rs +++ b/src/cli/download_handler.rs @@ -217,9 +217,20 @@ impl DownloadHandler { let spinner = Spinner::install_layout(); spinner.show(); + let mut error_msg = Vec::new(); + for exec in executables { - let _ = install(asset_name.to_string(), path, exec, destination.clone()) - .map_err(|x| HandlerError::new(x.to_string()))?; + let install_result = + install(asset_name.to_string(), path, exec, destination.clone()) + .map_err(|x| HandlerError::new(x.to_string())); + + match install_result { + Ok(output) => { + spinner.println(&Color::new(&output.to_string()).green().to_string()) + } + Err(HandlerError::Default(msg)) => error_msg.push(msg), + Err(x) => return Err(x), + } } std::fs::remove_file(path).map_err(|x| { HandlerError::new(format!( @@ -228,6 +239,15 @@ impl DownloadHandler { )) })?; + if !error_msg.is_empty() { + let mut message = String::new(); + for msg in error_msg { + message = format!("{}\n{}", message, Color::new(&msg).bold().red(),); + } + spinner.finish(); + return Err(HandlerError::new(message)); + } + let message = format!("{}\n", Color::new("Installation completed!").green()); spinner.finish_with_message(&message); Ok(())