Skip to content

Commit

Permalink
download_handler: add error handling for multiple executable install
Browse files Browse the repository at this point in the history
  • Loading branch information
duong-dt committed Oct 23, 2024
1 parent 5f04767 commit 41c124e
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/cli/download_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -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(())
Expand Down

0 comments on commit 41c124e

Please sign in to comment.