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

Remove environment variable suggestion from AuthorizationError #12628

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 3 additions & 9 deletions src/cargo/util/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{
sources::CRATES_IO_REGISTRY,
util::{config::ConfigKey, CanonicalUrl, CargoResult, Config, IntoUrl},
util::{CanonicalUrl, CargoResult, Config, IntoUrl},
};
use anyhow::{bail, Context as _};
use cargo_credential::{
Expand Down Expand Up @@ -372,19 +372,13 @@ impl fmt::Display for AuthorizationError {
} else {
""
};
write!(
f,
"{}, please run `cargo login{args}`\nor use environment variable CARGO_REGISTRY_TOKEN",
self.reason
)
write!(f, "{}, please run `cargo login{args}`", self.reason)
} else if let Some(name) = self.sid.alt_registry_key() {
let key = ConfigKey::from_str(&format!("registries.{name}.token"));
write!(
f,
"{} for `{}`, please run `cargo login --registry {name}`\nor use environment variable {}",
"{} for `{}`, please run `cargo login --registry {name}`",
self.reason,
self.sid.display_registry_name(),
key.as_env_key(),
)
} else if self.reason == AuthorizationErrorReason::TokenMissing {
write!(
Expand Down
12 changes: 4 additions & 8 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,7 @@ fn block_publish_due_to_no_token() {
.with_stderr(
"\
[UPDATING] `alternative` index
error: no token found for `alternative`, please run `cargo login --registry alternative`
or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN",
error: no token found for `alternative`, please run `cargo login --registry alternative`",
)
.run();
}
Expand All @@ -459,8 +458,7 @@ fn cargo_registries_crates_io_protocol() {
.with_stderr(
"\
[UPDATING] `alternative` index
error: no token found for `alternative`, please run `cargo login --registry alternative`
or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN",
error: no token found for `alternative`, please run `cargo login --registry alternative`",
)
.run();
}
Expand Down Expand Up @@ -1531,8 +1529,7 @@ fn warn_for_unused_fields() {
"\
[UPDATING] `alternative` index
[WARNING] unused config key `registries.alternative.unexpected-field` in `[..]config.toml`
[ERROR] no token found for `alternative`, please run `cargo login --registry alternative`
or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN",
[ERROR] no token found for `alternative`, please run `cargo login --registry alternative`",
)
.run();

Expand All @@ -1542,8 +1539,7 @@ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN",
"\
[UPDATING] crates.io index
[WARNING] unused config key `registry.unexpected-field` in `[..]config.toml`
[ERROR] no token found, please run `cargo login`
or use environment variable CARGO_REGISTRY_TOKEN",
[ERROR] no token found, please run `cargo login`",
)
.run();
}
3 changes: 0 additions & 3 deletions tests/testsuite/credential_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ fn gated() {
"\
[UPDATING] [..]
[ERROR] no token found, please run `cargo login`
or use environment variable CARGO_REGISTRY_TOKEN
",
)
.run();
Expand All @@ -58,7 +57,6 @@ or use environment variable CARGO_REGISTRY_TOKEN
"\
[UPDATING] [..]
[ERROR] no token found for `alternative`, please run `cargo login --registry alternative`
or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
",
)
.run();
Expand Down Expand Up @@ -354,7 +352,6 @@ fn all_not_found() {

Caused by:
no token found, please run `cargo login`
or use environment variable CARGO_REGISTRY_TOKEN
"#,
)
.run();
Expand Down
4 changes: 0 additions & 4 deletions tests/testsuite/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3224,7 +3224,6 @@ fn default_auth_error() {
"\
[UPDATING] crates.io index
error: no token found, please run `cargo login`
or use environment variable CARGO_REGISTRY_TOKEN
",
)
.with_status(101)
Expand All @@ -3236,7 +3235,6 @@ or use environment variable CARGO_REGISTRY_TOKEN
"\
[UPDATING] `alternative` index
error: no token found for `alternative`, please run `cargo login --registry alternative`
or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
",
)
.with_status(101)
Expand All @@ -3258,7 +3256,6 @@ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
"\
[UPDATING] `alternative` index
error: no token found for `alternative`, please run `cargo login --registry alternative`
or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
",
)
.with_status(101)
Expand All @@ -3270,7 +3267,6 @@ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
"\
[UPDATING] crates.io index
error: no token found, please run `cargo login --registry crates-io`
or use environment variable CARGO_REGISTRY_TOKEN
",
)
.with_status(101)
Expand Down
7 changes: 2 additions & 5 deletions tests/testsuite/registry_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ fn missing_token() {
[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..])`

Caused by:
no token found for `alternative`, please run `cargo login --registry alternative`
or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN",
no token found for `alternative`, please run `cargo login --registry alternative`",
)
.run();
}
Expand All @@ -273,8 +272,7 @@ Caused by:
unable to get packages from source

Caused by:
no token found for `alternative`, please run `cargo login --registry alternative`
or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN",
no token found for `alternative`, please run `cargo login --registry alternative`",
)
.run();
}
Expand All @@ -299,7 +297,6 @@ fn incorrect_token() {

Caused by:
token rejected for `alternative`, please run `cargo login --registry alternative`
or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN

Caused by:
failed to get successful HTTP response from `http://[..]/index/config.json`, got 401
Expand Down