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

Improve the error message if publish is false or empty list #11280

Merged
merged 3 commits into from
Oct 24, 2022
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
10 changes: 8 additions & 2 deletions src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,16 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
let reg_name = publish_registry
.clone()
.unwrap_or_else(|| CRATES_IO_REGISTRY.to_string());
if !allowed_registries.contains(&reg_name) {
if allowed_registries.is_empty() {
bail!(
"`{}` cannot be published.\n\
The registry `{}` is not listed in the `publish` value in Cargo.toml.",
`package.publish` is set to `false` or an empty list in Cargo.toml and prevents publishing.",
pkg.name(),
);
} else if !allowed_registries.contains(&reg_name) {
bail!(
"`{}` cannot be published.\n\
The registry `{}` is not listed in the `package.publish` value in Cargo.toml.",
pkg.name(),
reg_name
);
Expand Down
12 changes: 6 additions & 6 deletions tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ fn unpublishable_crate() {
.with_stderr(
"\
[ERROR] `foo` cannot be published.
The registry `crates-io` is not listed in the `publish` value in Cargo.toml.
`package.publish` is set to `false` or an empty list in Cargo.toml and prevents publishing.
",
)
.run();
Expand Down Expand Up @@ -655,7 +655,7 @@ fn registry_not_in_publish_list() {
.with_stderr(
"\
[ERROR] `foo` cannot be published.
The registry `alternative` is not listed in the `publish` value in Cargo.toml.
The registry `alternative` is not listed in the `package.publish` value in Cargo.toml.
",
)
.run();
Expand Down Expand Up @@ -684,7 +684,7 @@ fn publish_empty_list() {
.with_stderr(
"\
[ERROR] `foo` cannot be published.
The registry `alternative` is not listed in the `publish` value in Cargo.toml.
`package.publish` is set to `false` or an empty list in Cargo.toml and prevents publishing.
",
)
.run();
Expand Down Expand Up @@ -819,7 +819,7 @@ fn publish_fail_with_no_registry_specified() {
.with_stderr(
"\
[ERROR] `foo` cannot be published.
The registry `crates-io` is not listed in the `publish` value in Cargo.toml.
The registry `crates-io` is not listed in the `package.publish` value in Cargo.toml.
",
)
.run();
Expand Down Expand Up @@ -848,7 +848,7 @@ fn block_publish_no_registry() {
.with_stderr(
"\
[ERROR] `foo` cannot be published.
The registry `alternative` is not listed in the `publish` value in Cargo.toml.
`package.publish` is set to `false` or an empty list in Cargo.toml and prevents publishing.
",
)
.run();
Expand Down Expand Up @@ -880,7 +880,7 @@ fn publish_with_crates_io_explicit() {
.with_stderr(
"\
[ERROR] `foo` cannot be published.
The registry `alternative` is not listed in the `publish` value in Cargo.toml.
The registry `alternative` is not listed in the `package.publish` value in Cargo.toml.
",
)
.run();
Expand Down