diff --git a/e2e/cli/test_lock_resolution_failure b/e2e/cli/test_lock_resolution_failure new file mode 100644 index 00000000000..243e43e7961 --- /dev/null +++ b/e2e/cli/test_lock_resolution_failure @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +export MISE_LOCKFILE=1 + +cat <mise.toml +[tools] +dummy = "3.0.0" +EOF + +cat <mise.lock +$LOCKFILE_HEADER + +[[tools.dummy]] +version = "1.0.0" +backend = "asdf:dummy" + +[tools.dummy.platforms.linux-x64] +checksum = "sha256:old" +EOF + +mise cache clear dummy + +assert_fail_contains "RTX_FAILURE=1 mise lock dummy --platform linux-x64 2>&1" "failed to resolve" +assert_contains "cat mise.lock" 'version = "1.0.0"' +assert_not_contains "cat mise.lock" 'version = "3.0.0"' + +assert_fail_contains "RTX_FAILURE=1 mise lock --platform linux-x64 2>&1" "failed to resolve" +assert_contains "cat mise.lock" 'version = "1.0.0"' +assert_not_contains "cat mise.lock" 'version = "3.0.0"' + +cat <mise.toml +[tools] +dummy = "3.0.0" +jq = "1.7.1" +EOF + +cat <mise.lock +$LOCKFILE_HEADER + +[[tools.dummy]] +version = "1.0.0" +backend = "asdf:dummy" + +[tools.dummy.platforms.linux-x64] +checksum = "sha256:old" +EOF + +output=$(RTX_FAILURE=1 mise lock jq --platform linux-x64 2>&1) +assert_contains "echo '$output'" "Processing 1 tool(s)" +assert_not_contains "echo '$output'" "failed to resolve dummy@3.0.0" +assert_contains "cat mise.lock" 'version = "1.7.1"' +assert_not_contains "cat mise.lock" 'version = "3.0.0"' diff --git a/src/cli/lock.rs b/src/cli/lock.rs index 8e6f02d8640..b52547f7ba3 100644 --- a/src/cli/lock.rs +++ b/src/cli/lock.rs @@ -19,6 +19,10 @@ use tokio::task::JoinSet; /// A tool to lock for a specific lockfile target. type LockTool = (crate::cli::args::BackendArg, crate::toolset::ToolVersion); +fn request_matches(a: &ToolRequest, b: &ToolRequest) -> bool { + a.version() == b.version() && a.options() == b.options() +} + /// Update lockfile checksums and URLs for all specified platforms /// /// Updates checksums and download URLs for all platforms already specified in the lockfile. @@ -108,7 +112,7 @@ impl Lock { config_paths, &lock_resolve_options, ) - .await; + .await?; if tools.is_empty() { // `tools` can be empty either because config has no tools, or because a filter excludes all. @@ -505,7 +509,7 @@ impl Lock { target_lockfile_path: &Path, config_paths: &[PathBuf], base_resolve_options: &ResolveOptions, - ) -> Vec { + ) -> Result> { let config_paths_set: BTreeSet<&PathBuf> = config_paths.iter().collect(); let mut all_tools: Vec = Vec::new(); @@ -564,8 +568,7 @@ impl Lock { let mut matched_resolved = false; if let Some(resolved_tv) = ts.versions.get(ba.as_ref()) { for tv in &resolved_tv.versions { - if tv.request.version() == request.version() - && tv.request.options() == request.options() + if request_matches(&tv.request, request) && tv.version != "latest" { matched_resolved = true; @@ -576,20 +579,38 @@ impl Lock { } } } + let requested_tool = self.tool.is_empty() + || self.tool.iter().any(|tool| tool.ba.short == ba.short); + let active_unresolved = requested_tool + && ts.versions.get(ba.as_ref()).is_some_and(|tvl| { + tvl.requests + .iter() + .any(|active| request_matches(active, request)) + }); // Resolve overridden requests through the same path as active // tools when the request cannot be copied from the resolved // toolset. Keep this broad only for idiomatic version files; // other sources preserve the previous latest-only behavior. - let should_resolve_overridden = - request.version() == "latest" || source.is_idiomatic_version_file(); + let should_resolve_overridden = active_unresolved + || request.version() == "latest" + || source.is_idiomatic_version_file(); if !matched_resolved && should_resolve_overridden { let mut resolve_options = match request .resolve_options(base_resolve_options) { Ok(opts) => opts, Err(err) => { - debug!("failed to resolve options for {request}: {err}"); - continue; + if active_unresolved { + return Err(err.wrap_err(format!( + "failed to resolve options for {request} for lockfile {}", + display_path(target_lockfile_path) + ))); + } else { + debug!( + "failed to resolve options for {request}: {err}" + ); + continue; + } } }; resolve_options.use_locked_version = false; @@ -604,7 +625,14 @@ impl Lock { } } Err(err) => { - debug!("failed to resolve overridden {request}: {err}"); + if active_unresolved { + return Err(err.wrap_err(format!( + "failed to resolve {request} for lockfile {}", + display_path(target_lockfile_path) + ))); + } else { + debug!("failed to resolve overridden {request}: {err}"); + } } } } @@ -615,7 +643,7 @@ impl Lock { } if self.tool.is_empty() { - all_tools + Ok(all_tools) } else { // Build map of tool args with explicit versions let specified_versions: std::collections::HashMap> = self @@ -671,7 +699,7 @@ impl Lock { // Deduplicate after potential "latest" -> concrete-version resolution. let mut seen_after: BTreeSet<(String, String)> = BTreeSet::new(); tools.retain(|(ba, tv)| seen_after.insert((ba.short.clone(), tv.version.clone()))); - tools + Ok(tools) } }