From e16952a2c4e34765b820068f218d2462d69127ed Mon Sep 17 00:00:00 2001 From: Michael-F-Bryan Date: Mon, 19 Jun 2023 14:26:42 +0800 Subject: [PATCH] Error out when the only versions matching a constraint are archived --- lib/wasix/src/runtime/resolver/wapm_source.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/wasix/src/runtime/resolver/wapm_source.rs b/lib/wasix/src/runtime/resolver/wapm_source.rs index 0206852e339..7a4cffe4d90 100644 --- a/lib/wasix/src/runtime/resolver/wapm_source.rs +++ b/lib/wasix/src/runtime/resolver/wapm_source.rs @@ -161,6 +161,7 @@ impl Source for WapmSource { Some(WapmWebQueryGetPackage { versions }) => versions, None => return Ok(Vec::new()), }; + let mut archived_versions = Vec::new(); for pkg_version in versions { tracing::trace!(?pkg_version, "checking package version"); @@ -171,6 +172,7 @@ impl Source for WapmSource { pkg.version=%version, "Skipping an archived version", ); + archived_versions.push(version); continue; } @@ -188,6 +190,25 @@ impl Source for WapmSource { } } + if summaries.is_empty() { + match archived_versions.as_slice() { + [] => { + // looks like this package couldn't be satisfied at all. + } + [version] => { + anyhow::bail!( + "The only version satisfying the constraint, {version}, is archived" + ); + } + [first, rest @ ..] => { + let num_others = rest.len(); + anyhow::bail!( + "Unable to satisfy the request, {first}, and {num_others} are all archived" + ); + } + } + } + Ok(summaries) } }