Skip to content

Commit 19d37d2

Browse files
committed
Auto merge of #11280 - hi-rustin:rustin-patch-error-msg, r=weihanglo
Improve the error message if `publish` is `false` or empty list ### What does this PR try to resolve? close #11262 Improve the error message if `publish` is the false or empty list. Say `publish` is set to `false` or an empty list in Cargo.toml and prevents publishing. ### How should we test and review this PR? Unit test ### Additional information If there was a way we could tell `publish` to be empty or `false`, I think it would get better. If you know an easy way to implement it, please feel free to comment.
2 parents 6e9da76 + 6c9f36d commit 19d37d2

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/cargo/ops/registry.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,16 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
134134
let reg_name = publish_registry
135135
.clone()
136136
.unwrap_or_else(|| CRATES_IO_REGISTRY.to_string());
137-
if !allowed_registries.contains(&reg_name) {
137+
if allowed_registries.is_empty() {
138138
bail!(
139139
"`{}` cannot be published.\n\
140-
The registry `{}` is not listed in the `publish` value in Cargo.toml.",
140+
`package.publish` is set to `false` or an empty list in Cargo.toml and prevents publishing.",
141+
pkg.name(),
142+
);
143+
} else if !allowed_registries.contains(&reg_name) {
144+
bail!(
145+
"`{}` cannot be published.\n\
146+
The registry `{}` is not listed in the `package.publish` value in Cargo.toml.",
141147
pkg.name(),
142148
reg_name
143149
);

tests/testsuite/publish.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ fn unpublishable_crate() {
325325
.with_stderr(
326326
"\
327327
[ERROR] `foo` cannot be published.
328-
The registry `crates-io` is not listed in the `publish` value in Cargo.toml.
328+
`package.publish` is set to `false` or an empty list in Cargo.toml and prevents publishing.
329329
",
330330
)
331331
.run();
@@ -655,7 +655,7 @@ fn registry_not_in_publish_list() {
655655
.with_stderr(
656656
"\
657657
[ERROR] `foo` cannot be published.
658-
The registry `alternative` is not listed in the `publish` value in Cargo.toml.
658+
The registry `alternative` is not listed in the `package.publish` value in Cargo.toml.
659659
",
660660
)
661661
.run();
@@ -684,7 +684,7 @@ fn publish_empty_list() {
684684
.with_stderr(
685685
"\
686686
[ERROR] `foo` cannot be published.
687-
The registry `alternative` is not listed in the `publish` value in Cargo.toml.
687+
`package.publish` is set to `false` or an empty list in Cargo.toml and prevents publishing.
688688
",
689689
)
690690
.run();
@@ -819,7 +819,7 @@ fn publish_fail_with_no_registry_specified() {
819819
.with_stderr(
820820
"\
821821
[ERROR] `foo` cannot be published.
822-
The registry `crates-io` is not listed in the `publish` value in Cargo.toml.
822+
The registry `crates-io` is not listed in the `package.publish` value in Cargo.toml.
823823
",
824824
)
825825
.run();
@@ -848,7 +848,7 @@ fn block_publish_no_registry() {
848848
.with_stderr(
849849
"\
850850
[ERROR] `foo` cannot be published.
851-
The registry `alternative` is not listed in the `publish` value in Cargo.toml.
851+
`package.publish` is set to `false` or an empty list in Cargo.toml and prevents publishing.
852852
",
853853
)
854854
.run();
@@ -880,7 +880,7 @@ fn publish_with_crates_io_explicit() {
880880
.with_stderr(
881881
"\
882882
[ERROR] `foo` cannot be published.
883-
The registry `alternative` is not listed in the `publish` value in Cargo.toml.
883+
The registry `alternative` is not listed in the `package.publish` value in Cargo.toml.
884884
",
885885
)
886886
.run();

0 commit comments

Comments
 (0)