From 72e94b524a43029a325d35409137aefc92ee9176 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Fri, 1 Nov 2024 13:45:40 -0700 Subject: [PATCH 1/5] Fix version. --- CHANGELOG.md | 6 ++++++ crates/core/src/helpers.rs | 10 +++++++++- crates/core/src/tool.rs | 12 ++---------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39b1a9367..c05d2a8e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,12 @@ - [Rust](https://github.com/moonrepo/tools/blob/master/tools/rust/CHANGELOG.md) - [Schema (TOML, JSON, YAML)](https://github.com/moonrepo/tools/blob/master/tools/internal-schema/CHANGELOG.md) +## Unreleased + +#### 🐞 Fixes + +- Fixed the wrong `proto_version` being passed to WASM function calls. + ## 0.42.0 #### 💥 Breaking diff --git a/crates/core/src/helpers.rs b/crates/core/src/helpers.rs index aae5b8fca..ba85d0ae3 100644 --- a/crates/core/src/helpers.rs +++ b/crates/core/src/helpers.rs @@ -22,7 +22,15 @@ pub static ENV_VAR_SUB: LazyLock = pub fn get_proto_version() -> &'static Version { static VERSION_CACHE: OnceLock = OnceLock::new(); - VERSION_CACHE.get_or_init(|| Version::parse(env!("CARGO_PKG_VERSION")).unwrap()) + VERSION_CACHE.get_or_init(|| { + Version::parse( + env::var("PROTO_VERSION") + .ok() + .as_deref() + .unwrap_or_else(|| env!("CARGO_PKG_VERSION")), + ) + .unwrap() + }) } pub fn is_offline() -> bool { diff --git a/crates/core/src/tool.rs b/crates/core/src/tool.rs index c0772d5cd..7cfe259f2 100644 --- a/crates/core/src/tool.rs +++ b/crates/core/src/tool.rs @@ -211,17 +211,9 @@ impl Tool { #[cfg(not(debug_assertions))] if let Some(expected_version) = &metadata.minimum_proto_version { - use miette::IntoDiagnostic; + let actual_version = get_proto_version(); - let actual_version = Version::parse( - std::env::var("PROTO_VERSION") - .ok() - .as_deref() - .unwrap_or_else(|| env!("CARGO_PKG_VERSION")), - ) - .into_diagnostic()?; - - if &actual_version < expected_version { + if actual_version < expected_version { return Err(ProtoError::InvalidMinimumVersion { tool: metadata.name, id: self.id.clone(), From 080fad7214e262f543e6986f403f0c2b238cac18 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Mon, 11 Nov 2024 15:17:12 -0800 Subject: [PATCH 2/5] Add more logging. --- CHANGELOG.md | 4 +++ Cargo.lock | 40 ++++++++++++------------ Cargo.toml | 12 ++++---- crates/cli/src/commands/install.rs | 49 ++++++++++++++++++++++++------ crates/core/src/helpers.rs | 2 +- 5 files changed, 71 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c05d2a8e9..b4eb04a13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ ## Unreleased +#### 🚀 Updates + +- Added more logging to debug the "File exists (os error 17)" issue. + #### 🐞 Fixes - Fixed the wrong `proto_version` being passed to WASM function calls. diff --git a/Cargo.lock b/Cargo.lock index 0405c65c9..d655127fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1653,9 +1653,9 @@ dependencies = [ [[package]] name = "insta" -version = "1.41.0" +version = "1.41.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f72d3e19488cf7d8ea52d2fc0f8754fc933398b337cd3cbdb28aaeb35159ef" +checksum = "7e9ffc4d4892617c50a928c52b2961cb5174b6fc6ebf252b2fac9d21955c48b8" dependencies = [ "console", "lazy_static", @@ -3186,9 +3186,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "starbase" -version = "0.9.2" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e385f65a4012e542a9519f3914fba9a7b46eb2c8f015b2963356914eea815df1" +checksum = "b1b55189276998800e553d329ab7218e1a81688661901268a0cad0b774d6d70d" dependencies = [ "async-trait", "chrono", @@ -3202,9 +3202,9 @@ dependencies = [ [[package]] name = "starbase_archive" -version = "0.8.7" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ef6774ceaab5ff89017f475aa2b1db19998de5cc4df719ea65f1d5ba9b754e6" +checksum = "10c4a2d20383c76bb79b369a1ce9bdecd33d3be283118ebfeaa7ef7bf9f8d9e0" dependencies = [ "binstall-tar", "bzip2", @@ -3222,9 +3222,9 @@ dependencies = [ [[package]] name = "starbase_sandbox" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42da00b3ca0f2fe52e18416ed5b2d44c82e85351bcf797431aa1da5af903ee7c" +checksum = "79016af930d642aa6facd64e52b77e7635a3c3f7ced7478fd023c327a266293c" dependencies = [ "assert_cmd", "assert_fs", @@ -3237,9 +3237,9 @@ dependencies = [ [[package]] name = "starbase_shell" -version = "0.5.8" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfcf49fdd3aa2a87175defb63325540f61346fc28e03bbbbdf56eff96025252f" +checksum = "dc0ebf0adaea675a16772903263bcad0433beeebc2a0f64ec4e9fbcf68d3261e" dependencies = [ "miette", "regex", @@ -3250,9 +3250,9 @@ dependencies = [ [[package]] name = "starbase_styles" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49d8a8222c97b23595fe393ac35d62b88942bdc7e89c8c88736d9ea2c986dbae" +checksum = "358d0e98dc524ef2b838e9e70367c899d5ef8629f4efb44add57d92da6e75a8f" dependencies = [ "dirs 5.0.1", "miette", @@ -3262,9 +3262,9 @@ dependencies = [ [[package]] name = "starbase_utils" -version = "0.8.10" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302be829660e306e56225a20224b1ddcce97baae9c34a62742e8ac7d122f6508" +checksum = "599f8f6eff8c1a7cf770e2a68447140128255a9c10a6dfd58b29e7e766177c56" dependencies = [ "dirs 5.0.1", "fs4", @@ -3344,9 +3344,9 @@ checksum = "b7401a30af6cb5818bb64852270bb722533397edcfc7344954a38f420819ece2" [[package]] name = "syn" -version = "2.0.85" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -3480,18 +3480,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.65" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.65" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 454d36a97..411d3b65d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,8 +29,8 @@ serde = { version = "1.0.214", features = ["derive"] } serde_json = "1.0.132" sha2 = "0.10.8" shell-words = "1.1.0" -starbase = { version = "0.9.2" } -starbase_archive = { version = "0.8.7", features = [ +starbase = { version = "0.9.4" } +starbase_archive = { version = "0.8.8", features = [ "gz", "miette", "tar-bz2", @@ -41,10 +41,10 @@ starbase_archive = { version = "0.8.7", features = [ "zip-deflate", ] } starbase_events = { version = "0.6.3" } -starbase_sandbox = { version = "0.7.4" } -starbase_shell = { version = "0.5.8", features = ["miette"] } -starbase_styles = { version = "0.4.4" } -starbase_utils = { version = "0.8.10", default-features = false, features = [ +starbase_sandbox = { version = "0.7.5" } +starbase_shell = { version = "0.5.9", features = ["miette"] } +starbase_styles = { version = "0.4.5" } +starbase_utils = { version = "0.8.11", default-features = false, features = [ "json", "miette", "net", diff --git a/crates/cli/src/commands/install.rs b/crates/cli/src/commands/install.rs index 65bb2d3ab..006829d67 100644 --- a/crates/cli/src/commands/install.rs +++ b/crates/cli/src/commands/install.rs @@ -16,7 +16,7 @@ use std::env; use std::time::Duration; use tokio::task::JoinSet; use tokio::time::sleep; -use tracing::{debug, instrument}; +use tracing::{debug, instrument, trace}; #[derive(Args, Clone, Debug, Default)] pub struct InstallArgs { @@ -435,12 +435,14 @@ pub async fn install_all(session: &ProtoSession) -> AppResult { for mut tool in tools { if let Some(version) = versions.remove(&tool.id) { + let tool_id = tool.id.clone(); + let pb = mpb.add(ProgressBar::new(0)); pb.set_style(pbs.clone()); // Defer writing content till the thread starts, // otherwise the progress bars fail to render correctly - set.spawn(async move { + let handle = set.spawn(async move { sleep(Duration::from_millis(25)).await; pb.set_prefix(color::id(format!( @@ -463,23 +465,52 @@ pub async fn install_all(session: &ProtoSession) -> AppResult { ) .await }); + + trace!( + task_id = handle.id().to_string(), + "Spawning {} in background task", + color::id(tool_id) + ); } } let total = set.len(); + let mut maybe_error: Option = None; - while let Some(result) = set.join_next().await { - match result.into_diagnostic() { - Err(error) | Ok(Err(error)) => { - mpb.clear().into_diagnostic()?; - drop(mpb); + while let Some(result) = set.join_next_with_id().await { + match result { + Err(error) => { + trace!(task_id = error.id().to_string(), "Spawned task failed"); - return Err(error); + 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" + ); + + maybe_error = Some(error); + break; + } + Ok((task_id, Ok(_))) => { + trace!(task_id = task_id.to_string(), "Spawned task successful"); } - _ => {} }; } + if let Some(error) = maybe_error { + trace!("Shutting down currently running background tasks as an error has occurred"); + + mpb.clear().into_diagnostic()?; + 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); diff --git a/crates/core/src/helpers.rs b/crates/core/src/helpers.rs index ba85d0ae3..12691ab07 100644 --- a/crates/core/src/helpers.rs +++ b/crates/core/src/helpers.rs @@ -27,7 +27,7 @@ pub fn get_proto_version() -> &'static Version { env::var("PROTO_VERSION") .ok() .as_deref() - .unwrap_or_else(|| env!("CARGO_PKG_VERSION")), + .unwrap_or(env!("CARGO_PKG_VERSION")), ) .unwrap() }) From 20053cd580902a27dbb027f029449f27285380d1 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Mon, 11 Nov 2024 15:19:44 -0800 Subject: [PATCH 3/5] Swallow error. --- crates/cli/src/commands/install.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cli/src/commands/install.rs b/crates/cli/src/commands/install.rs index 006829d67..3142b66e1 100644 --- a/crates/cli/src/commands/install.rs +++ b/crates/cli/src/commands/install.rs @@ -503,7 +503,7 @@ pub async fn install_all(session: &ProtoSession) -> AppResult { if let Some(error) = maybe_error { trace!("Shutting down currently running background tasks as an error has occurred"); - mpb.clear().into_diagnostic()?; + let _ = mpb.clear(); drop(mpb); set.shutdown().await; From 191b82b6f5744c2d9f7df298d156b76056acc9fa Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Mon, 11 Nov 2024 16:30:10 -0800 Subject: [PATCH 4/5] 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?; From 04c64330e661c035c16adad3e36d4f6ef84e39aa Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Mon, 11 Nov 2024 16:31:14 -0800 Subject: [PATCH 5/5] Remove title. --- crates/cli/src/commands/install.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cli/src/commands/install.rs b/crates/cli/src/commands/install.rs index bd01ad6f8..ffb5809fe 100644 --- a/crates/cli/src/commands/install.rs +++ b/crates/cli/src/commands/install.rs @@ -463,7 +463,7 @@ pub async fn install_all(session: &ProtoSession) -> AppResult { ) .await { - pb.set_message(format!("Failed to install {}: {}", tool.get_name(), error)); + pb.set_message(format!("Failed to install: {}", error)); print_progress_state(&pb); } });