From 191b82b6f5744c2d9f7df298d156b76056acc9fa Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Mon, 11 Nov 2024 16:30:10 -0800 Subject: [PATCH] Dont error in multi install. --- CHANGELOG.md | 1 + crates/cli/src/commands/install.rs | 55 +++++++++++++----------------- crates/cli/src/commands/run.rs | 9 ++--- crates/cli/src/commands/upgrade.rs | 12 ++++--- 4 files changed, 34 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4eb04a13..8ec309769 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ #### 🚀 Updates +- When installing many tools with `proto install|use`, a failed install for a single tool will no longer abort the install of the other tools. - Added more logging to debug the "File exists (os error 17)" issue. #### 🐞 Fixes diff --git a/crates/cli/src/commands/install.rs b/crates/cli/src/commands/install.rs index 3142b66e1..bd01ad6f8 100644 --- a/crates/cli/src/commands/install.rs +++ b/crates/cli/src/commands/install.rs @@ -5,7 +5,6 @@ use crate::shell::{self, Export}; use crate::telemetry::{track_usage, Metric}; use clap::Args; use indicatif::ProgressBar; -use miette::IntoDiagnostic; use proto_core::flow::install::{InstallOptions, InstallPhase}; use proto_core::{Id, PinType, Tool, UnresolvedVersionSpec, VersionSpec, PROTO_PLUGIN_KEY}; use proto_pdk_api::{InstallHook, SyncShellProfileInput, SyncShellProfileOutput}; @@ -198,7 +197,7 @@ async fn update_shell(tool: &Tool, passthrough_args: Vec) -> miette::Res pub async fn do_install( tool: &mut Tool, args: InstallArgs, - pb: ProgressBar, + pb: &ProgressBar, ) -> miette::Result { let version = args.get_unresolved_spec(); let pin_type = args.get_pin_type(); @@ -375,7 +374,7 @@ async fn install_one(session: &ProtoSession, id: &Id, args: InstallArgs) -> miet let mut tool = session.load_tool(id).await?; let pb = create_progress_bar(format!("Installing {}", tool.get_name())); - if do_install(&mut tool, args, pb).await? { + if do_install(&mut tool, args, &pb).await? { println!( "{} {} has been installed to {}!", tool.get_name(), @@ -452,18 +451,21 @@ pub async fn install_all(session: &ProtoSession) -> AppResult { ))); pb.set_message(format!("Installing {} {}", tool.get_name(), version)); - print_progress_state(&pb); - do_install( + if let Err(error) = do_install( &mut tool, InstallArgs { spec: Some(version), ..Default::default() }, - pb, + &pb, ) .await + { + pb.set_message(format!("Failed to install {}: {}", tool.get_name(), error)); + print_progress_state(&pb); + } }); trace!( @@ -474,46 +476,35 @@ pub async fn install_all(session: &ProtoSession) -> AppResult { } } - let total = set.len(); - let mut maybe_error: Option = None; + let mut installed_count = 0; + let mut failed_count = 0; while let Some(result) = set.join_next_with_id().await { match result { Err(error) => { - trace!(task_id = error.id().to_string(), "Spawned task failed"); - - maybe_error = Err(error).into_diagnostic().ok(); - break; - } - Ok((task_id, Err(error))) => { trace!( - task_id = task_id.to_string(), - "Spawned task successful but with an error" + task_id = error.id().to_string(), + "Spawned task failed: {}", + error ); - - maybe_error = Some(error); - break; + failed_count += 1; } - Ok((task_id, Ok(_))) => { + Ok((task_id, _)) => { trace!(task_id = task_id.to_string(), "Spawned task successful"); + installed_count += 1; } }; } - if let Some(error) = maybe_error { - trace!("Shutting down currently running background tasks as an error has occurred"); - - let _ = mpb.clear(); - drop(mpb); - - set.shutdown().await; - - return Err(error); - } - // When no TTY, we should display something to the user! if mpb.is_hidden() { - println!("Successfully installed {} tools!", total); + if installed_count > 0 { + println!("Successfully installed {} tools!", installed_count); + } + + if failed_count > 0 { + println!("Failed to install {} tools!", failed_count); + } } Ok(None) diff --git a/crates/cli/src/commands/run.rs b/crates/cli/src/commands/run.rs index 98a690e23..3a30fa976 100644 --- a/crates/cli/src/commands/run.rs +++ b/crates/cli/src/commands/run.rs @@ -191,12 +191,9 @@ pub async fn run(session: ProtoSession, args: RunArgs) -> AppResult { ..Default::default() }; - do_install( - &mut tool, - install_args, - create_progress_bar(format!("Installing {resolved_version}")), - ) - .await?; + let pb = create_progress_bar(format!("Installing {resolved_version}")); + + do_install(&mut tool, install_args, &pb).await?; println!( "{} {} has been installed, continuing execution...", diff --git a/crates/cli/src/commands/upgrade.rs b/crates/cli/src/commands/upgrade.rs index 3636f2f29..87f2a7576 100644 --- a/crates/cli/src/commands/upgrade.rs +++ b/crates/cli/src/commands/upgrade.rs @@ -118,6 +118,12 @@ pub async fn upgrade(session: ProtoSession, args: UpgradeArgs) -> AppResult { // Load the tool and install the new version let mut tool = session.load_proto_tool().await?; + let pb = create_progress_bar(if target_version > current_version { + format!("Upgrading to {}", target_version) + } else { + format!("Downgrading to {}", target_version) + }); + do_install( &mut tool, InstallArgs { @@ -127,11 +133,7 @@ pub async fn upgrade(session: ProtoSession, args: UpgradeArgs) -> AppResult { ))), ..Default::default() }, - create_progress_bar(if target_version > current_version { - format!("Upgrading to {}", target_version) - } else { - format!("Downgrading to {}", target_version) - }), + &pb, ) .await?;