Skip to content

Commit f0bb1cc

Browse files
committed
fix: Expand error messages around path dependency on cargo package and cargo publish
1 parent 409fed7 commit f0bb1cc

File tree

6 files changed

+64
-29
lines changed

6 files changed

+64
-29
lines changed

src/cargo/ops/cargo_package/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::sources::{PathSource, CRATES_IO_REGISTRY};
2424
use crate::util::cache_lock::CacheLockMode;
2525
use crate::util::context::JobsConfig;
2626
use crate::util::errors::CargoResult;
27+
use crate::util::errors::ManifestError;
2728
use crate::util::restricted_names;
2829
use crate::util::toml::prepare_for_publish;
2930
use crate::util::FileLock;
@@ -133,7 +134,13 @@ fn create_package(
133134

134135
// Check that the package dependencies are safe to deploy.
135136
for dep in pkg.dependencies() {
136-
super::check_dep_has_version(dep, false)?;
137+
super::check_dep_has_version(dep, false)
138+
.map_err(|err| {
139+
ManifestError::new(
140+
err.context(format!("failed to verify manifest at `{}`", pkg.manifest_path().display())),
141+
pkg.manifest_path().into(),
142+
)
143+
})?;
137144
}
138145

139146
let filename = pkg.package_id().tarball_name();

src/cargo/ops/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fn check_dep_has_version(dep: &crate::core::Dependency, publish: bool) -> crate:
9090
|registry_id| registry_id.display_registry_name(),
9191
);
9292
anyhow::bail!(
93-
"all dependencies must have a version specified when {}.\n\
93+
"all dependencies must have a version requirement specified when {}.\n\
9494
dependency `{}` does not specify a version\n\
9595
Note: The {} dependency will use the version from {},\n\
9696
the `{}` specification will be removed from the dependency declaration.",

src/cargo/ops/registry/publish.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use crate::sources::CRATES_IO_REGISTRY;
4343
use crate::util::auth;
4444
use crate::util::cache_lock::CacheLockMode;
4545
use crate::util::context::JobsConfig;
46+
use crate::util::errors::ManifestError;
4647
use crate::util::toml::prepare_for_publish;
4748
use crate::util::Graph;
4849
use crate::util::Progress;
@@ -171,7 +172,13 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
171172

172173
for (pkg, _) in &pkgs {
173174
verify_unpublished(pkg, &mut source, &source_ids, opts.dry_run, opts.gctx)?;
174-
verify_dependencies(pkg, &registry, source_ids.original)?;
175+
verify_dependencies(pkg, &registry, source_ids.original)
176+
.map_err(|err| {
177+
ManifestError::new(
178+
err.context(format!("failed to verify manifest at `{}`", pkg.manifest_path().display())),
179+
pkg.manifest_path().into(),
180+
)
181+
})?;
175182
}
176183
}
177184

tests/testsuite/alt_registry.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,12 @@ fn cannot_publish_to_crates_io_with_registry_dependency() {
288288
.with_status(101)
289289
.with_stderr_data(str![[r#"
290290
[UPDATING] crates.io index
291-
[ERROR] crates cannot be published to crates.io with dependencies sourced from other
292-
registries. `bar` needs to be published to crates.io before publishing this crate.
293-
(crate `bar` is pulled from registry `alternative`)
291+
[ERROR] failed to verify manifest at `[ROOT]/foo/Cargo.toml`
292+
293+
Caused by:
294+
crates cannot be published to crates.io with dependencies sourced from other
295+
registries. `bar` needs to be published to crates.io before publishing this crate.
296+
(crate `bar` is pulled from registry `alternative`)
294297
295298
"#]])
296299
.run();
@@ -304,9 +307,12 @@ registries. `bar` needs to be published to crates.io before publishing this crat
304307
.with_status(101)
305308
.with_stderr_data(str![[r#"
306309
[UPDATING] crates.io index
307-
[ERROR] crates cannot be published to crates.io with dependencies sourced from other
308-
registries. `bar` needs to be published to crates.io before publishing this crate.
309-
(crate `bar` is pulled from registry `alternative`)
310+
[ERROR] failed to verify manifest at `[ROOT]/foo/Cargo.toml`
311+
312+
Caused by:
313+
crates cannot be published to crates.io with dependencies sourced from other
314+
registries. `bar` needs to be published to crates.io before publishing this crate.
315+
(crate `bar` is pulled from registry `alternative`)
310316
311317
"#]])
312318
.run();

tests/testsuite/package.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,13 @@ fn path_dependency_no_version() {
368368
.with_stderr_data(str![[r#"
369369
[WARNING] manifest has no documentation, homepage or repository.
370370
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
371-
[ERROR] all dependencies must have a version specified when packaging.
372-
dependency `bar` does not specify a version
373-
Note: The packaged dependency will use the version from crates.io,
374-
the `path` specification will be removed from the dependency declaration.
371+
[ERROR] failed to verify manifest at `[ROOT]/foo/Cargo.toml`
372+
373+
Caused by:
374+
all dependencies must have a version requirement specified when packaging.
375+
dependency `bar` does not specify a version
376+
Note: The packaged dependency will use the version from crates.io,
377+
the `path` specification will be removed from the dependency declaration.
375378
376379
"#]])
377380
.run();
@@ -405,10 +408,13 @@ fn git_dependency_no_version() {
405408
.with_stderr_data(str![[r#"
406409
[WARNING] manifest has no documentation, homepage or repository.
407410
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
408-
[ERROR] all dependencies must have a version specified when packaging.
409-
dependency `foo` does not specify a version
410-
Note: The packaged dependency will use the version from crates.io,
411-
the `git` specification will be removed from the dependency declaration.
411+
[ERROR] failed to verify manifest at `[ROOT]/foo/Cargo.toml`
412+
413+
Caused by:
414+
all dependencies must have a version requirement specified when packaging.
415+
dependency `foo` does not specify a version
416+
Note: The packaged dependency will use the version from crates.io,
417+
the `git` specification will be removed from the dependency declaration.
412418
413419
"#]])
414420
.run();
@@ -2989,10 +2995,13 @@ src/main.rs
29892995
p.cargo("package")
29902996
.with_status(101)
29912997
.with_stderr_data(str![[r#"
2992-
[ERROR] all dependencies must have a version specified when packaging.
2993-
dependency `bar` does not specify a version
2994-
Note: The packaged dependency will use the version from crates.io,
2995-
the `path` specification will be removed from the dependency declaration.
2998+
[ERROR] failed to verify manifest at `[ROOT]/foo/Cargo.toml`
2999+
3000+
Caused by:
3001+
all dependencies must have a version requirement specified when packaging.
3002+
dependency `bar` does not specify a version
3003+
Note: The packaged dependency will use the version from crates.io,
3004+
the `path` specification will be removed from the dependency declaration.
29963005
29973006
"#]])
29983007
.run();

tests/testsuite/publish.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,13 @@ fn git_deps() {
398398
.with_status(101)
399399
.with_stderr_data(str![[r#"
400400
[UPDATING] crates.io index
401-
[ERROR] all dependencies must have a version specified when publishing.
402-
dependency `foo` does not specify a version
403-
Note: The published dependency will use the version from crates.io,
404-
the `git` specification will be removed from the dependency declaration.
401+
[ERROR] failed to verify manifest at `[ROOT]/foo/Cargo.toml`
402+
403+
Caused by:
404+
all dependencies must have a version requirement specified when publishing.
405+
dependency `foo` does not specify a version
406+
Note: The published dependency will use the version from crates.io,
407+
the `git` specification will be removed from the dependency declaration.
405408
406409
"#]])
407410
.run();
@@ -438,10 +441,13 @@ fn path_dependency_no_version() {
438441
.with_status(101)
439442
.with_stderr_data(str![[r#"
440443
[UPDATING] crates.io index
441-
[ERROR] all dependencies must have a version specified when publishing.
442-
dependency `bar` does not specify a version
443-
Note: The published dependency will use the version from crates.io,
444-
the `path` specification will be removed from the dependency declaration.
444+
[ERROR] failed to verify manifest at `[ROOT]/foo/Cargo.toml`
445+
446+
Caused by:
447+
all dependencies must have a version requirement specified when publishing.
448+
dependency `bar` does not specify a version
449+
Note: The published dependency will use the version from crates.io,
450+
the `path` specification will be removed from the dependency declaration.
445451
446452
"#]])
447453
.run();

0 commit comments

Comments
 (0)