Skip to content

Commit

Permalink
Dont error in multi install.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Nov 12, 2024
1 parent 20053cd commit 191b82b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 43 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 23 additions & 32 deletions crates/cli/src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -198,7 +197,7 @@ async fn update_shell(tool: &Tool, passthrough_args: Vec<String>) -> miette::Res
pub async fn do_install(
tool: &mut Tool,
args: InstallArgs,
pb: ProgressBar,
pb: &ProgressBar,
) -> miette::Result<bool> {
let version = args.get_unresolved_spec();
let pin_type = args.get_pin_type();
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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!(
Expand All @@ -474,46 +476,35 @@ pub async fn install_all(session: &ProtoSession) -> AppResult {
}
}

let total = set.len();
let mut maybe_error: Option<miette::Report> = 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)
Expand Down
9 changes: 3 additions & 6 deletions crates/cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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...",
Expand Down
12 changes: 7 additions & 5 deletions crates/cli/src/commands/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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?;

Expand Down

0 comments on commit 191b82b

Please sign in to comment.