Skip to content

fix: Expand error messages around path dependency on cargo package and cargo publish #15705

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

Merged
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
11 changes: 10 additions & 1 deletion src/cargo/ops/cargo_package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::sources::{PathSource, CRATES_IO_REGISTRY};
use crate::util::cache_lock::CacheLockMode;
use crate::util::context::JobsConfig;
use crate::util::errors::CargoResult;
use crate::util::errors::ManifestError;
use crate::util::restricted_names;
use crate::util::toml::prepare_for_publish;
use crate::util::FileLock;
Expand Down Expand Up @@ -133,7 +134,15 @@ fn create_package(

// Check that the package dependencies are safe to deploy.
for dep in pkg.dependencies() {
super::check_dep_has_version(dep, false)?;
super::check_dep_has_version(dep, false).map_err(|err| {
ManifestError::new(
err.context(format!(
"failed to verify manifest at `{}`",
pkg.manifest_path().display()
)),
pkg.manifest_path().into(),
)
})?;
}

let filename = pkg.package_id().tarball_name();
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn check_dep_has_version(dep: &crate::core::Dependency, publish: bool) -> crate:
|registry_id| registry_id.display_registry_name(),
);
anyhow::bail!(
"all dependencies must have a version specified when {}.\n\
"all dependencies must have a version requirement specified when {}.\n\
dependency `{}` does not specify a version\n\
Note: The {} dependency will use the version from {},\n\
the `{}` specification will be removed from the dependency declaration.",
Expand Down
11 changes: 10 additions & 1 deletion src/cargo/ops/registry/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use crate::sources::CRATES_IO_REGISTRY;
use crate::util::auth;
use crate::util::cache_lock::CacheLockMode;
use crate::util::context::JobsConfig;
use crate::util::errors::ManifestError;
use crate::util::toml::prepare_for_publish;
use crate::util::Graph;
use crate::util::Progress;
Expand Down Expand Up @@ -171,7 +172,15 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {

for (pkg, _) in &pkgs {
verify_unpublished(pkg, &mut source, &source_ids, opts.dry_run, opts.gctx)?;
verify_dependencies(pkg, &registry, source_ids.original)?;
verify_dependencies(pkg, &registry, source_ids.original).map_err(|err| {
ManifestError::new(
err.context(format!(
"failed to verify manifest at `{}`",
pkg.manifest_path().display()
)),
pkg.manifest_path().into(),
)
})?;
}
}

Expand Down
18 changes: 12 additions & 6 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,12 @@ fn cannot_publish_to_crates_io_with_registry_dependency() {
.with_status(101)
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
[ERROR] crates cannot be published to crates.io with dependencies sourced from other
registries. `bar` needs to be published to crates.io before publishing this crate.
(crate `bar` is pulled from registry `alternative`)
[ERROR] failed to verify manifest at `[ROOT]/foo/Cargo.toml`

Caused by:
crates cannot be published to crates.io with dependencies sourced from other
registries. `bar` needs to be published to crates.io before publishing this crate.
(crate `bar` is pulled from registry `alternative`)

"#]])
.run();
Expand All @@ -304,9 +307,12 @@ registries. `bar` needs to be published to crates.io before publishing this crat
.with_status(101)
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
[ERROR] crates cannot be published to crates.io with dependencies sourced from other
registries. `bar` needs to be published to crates.io before publishing this crate.
(crate `bar` is pulled from registry `alternative`)
[ERROR] failed to verify manifest at `[ROOT]/foo/Cargo.toml`

Caused by:
crates cannot be published to crates.io with dependencies sourced from other
registries. `bar` needs to be published to crates.io before publishing this crate.
(crate `bar` is pulled from registry `alternative`)

"#]])
.run();
Expand Down
33 changes: 21 additions & 12 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,13 @@ fn path_dependency_no_version() {
.with_stderr_data(str![[r#"
[WARNING] manifest has no documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
[ERROR] all dependencies must have a version specified when packaging.
dependency `bar` does not specify a version
Note: The packaged dependency will use the version from crates.io,
the `path` specification will be removed from the dependency declaration.
[ERROR] failed to verify manifest at `[ROOT]/foo/Cargo.toml`

Caused by:
all dependencies must have a version requirement specified when packaging.
dependency `bar` does not specify a version
Note: The packaged dependency will use the version from crates.io,
the `path` specification will be removed from the dependency declaration.

"#]])
.run();
Expand Down Expand Up @@ -405,10 +408,13 @@ fn git_dependency_no_version() {
.with_stderr_data(str![[r#"
[WARNING] manifest has no documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
[ERROR] all dependencies must have a version specified when packaging.
dependency `foo` does not specify a version
Note: The packaged dependency will use the version from crates.io,
the `git` specification will be removed from the dependency declaration.
[ERROR] failed to verify manifest at `[ROOT]/foo/Cargo.toml`

Caused by:
all dependencies must have a version requirement specified when packaging.
dependency `foo` does not specify a version
Note: The packaged dependency will use the version from crates.io,
the `git` specification will be removed from the dependency declaration.

"#]])
.run();
Expand Down Expand Up @@ -2989,10 +2995,13 @@ src/main.rs
p.cargo("package")
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] all dependencies must have a version specified when packaging.
dependency `bar` does not specify a version
Note: The packaged dependency will use the version from crates.io,
the `path` specification will be removed from the dependency declaration.
[ERROR] failed to verify manifest at `[ROOT]/foo/Cargo.toml`

Caused by:
all dependencies must have a version requirement specified when packaging.
dependency `bar` does not specify a version
Note: The packaged dependency will use the version from crates.io,
the `path` specification will be removed from the dependency declaration.

"#]])
.run();
Expand Down
22 changes: 14 additions & 8 deletions tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,13 @@ fn git_deps() {
.with_status(101)
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
[ERROR] all dependencies must have a version specified when publishing.
dependency `foo` does not specify a version
Note: The published dependency will use the version from crates.io,
the `git` specification will be removed from the dependency declaration.
[ERROR] failed to verify manifest at `[ROOT]/foo/Cargo.toml`

Caused by:
all dependencies must have a version requirement specified when publishing.
dependency `foo` does not specify a version
Note: The published dependency will use the version from crates.io,
the `git` specification will be removed from the dependency declaration.

"#]])
.run();
Expand Down Expand Up @@ -438,10 +441,13 @@ fn path_dependency_no_version() {
.with_status(101)
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
[ERROR] all dependencies must have a version specified when publishing.
dependency `bar` does not specify a version
Note: The published dependency will use the version from crates.io,
the `path` specification will be removed from the dependency declaration.
[ERROR] failed to verify manifest at `[ROOT]/foo/Cargo.toml`

Caused by:
all dependencies must have a version requirement specified when publishing.
dependency `bar` does not specify a version
Note: The published dependency will use the version from crates.io,
the `path` specification will be removed from the dependency declaration.

"#]])
.run();
Expand Down