Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix visibility validation to work when publishing a new package #4331

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions lib/registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ impl fmt::Display for QueryPackageError {
match self {
QueryPackageError::ErrorSendingQuery(q) => write!(f, "error sending query: {q}"),
QueryPackageError::NoPackageFound { name, version } => {
write!(f, "no package found for {name:?} (version = {version:?})")
write!(f, "no package found for {name:?}")?;
if let Some(version) = version {
write!(f, " (version = {version:?})")?;
}

Ok(())
}
}
}
Expand Down Expand Up @@ -170,9 +175,13 @@ pub fn query_package_from_registry(
QueryPackageError::ErrorSendingQuery(format!("Error sending GetPackagesQuery: {e}"))
})?;

let v = response.package_version.as_ref().ok_or_else(|| {
QueryPackageError::ErrorSendingQuery(format!("no package version for {name:?}"))
})?;
let v = response
.package_version
.as_ref()
.ok_or_else(|| QueryPackageError::NoPackageFound {
name: name.to_string(),
version: None,
})?;

let manifest = toml::from_str::<wasmer_toml::Manifest>(&v.manifest).map_err(|e| {
QueryPackageError::ErrorSendingQuery(format!("Invalid manifest for crate {name:?}: {e}"))
Expand Down
13 changes: 10 additions & 3 deletions lib/registry/src/package/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,14 +640,21 @@ mod validate {
registry: &str,
auth_token: &str,
) -> Result<bool, ValidationError> {
let package_version = crate::query_package_from_registry(
let result = crate::query_package_from_registry(
registry,
&manifest.package.name,
None,
Some(auth_token),
)?;
);

Ok(package_version.is_private != manifest.package.private)
match result {
Ok(package_version) => Ok(package_version.is_private != manifest.package.private),
Err(QueryPackageError::NoPackageFound { .. }) => {
// The package hasn't been published yet
Ok(false)
}
Err(e) => Err(e.into()),
}
}

fn validate_module(
Expand Down
Loading
Loading