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

fix: use channel-specific link for registry auth error #12709

Merged
merged 1 commit into from
Sep 20, 2023
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
21 changes: 13 additions & 8 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,15 +530,9 @@ impl Features {
}

let see_docs = || {
let url_channel = match channel().as_str() {
"dev" | "nightly" => "nightly/",
"beta" => "beta/",
_ => "",
};
format!(
"See https://doc.rust-lang.org/{}cargo/{} for more information \
about using this feature.",
url_channel, feature.docs
"See {} for more information about using this feature.",
cargo_docs_link(feature.docs)
)
};

Expand Down Expand Up @@ -1231,3 +1225,14 @@ pub fn channel() -> String {
fn cargo_use_gitoxide_instead_of_git2() -> bool {
std::env::var_os("__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2").map_or(false, |value| value == "1")
}

/// Generate a link to Cargo documentation for the current release channel
/// `path` is the URL component after `https://doc.rust-lang.org/{channel}/cargo/`
pub fn cargo_docs_link(path: &str) -> String {
let url_channel = match channel().as_str() {
"dev" | "nightly" => "nightly/",
"beta" => "beta/",
_ => "",
};
format!("https://doc.rust-lang.org/{url_channel}cargo/{path}")
}
4 changes: 3 additions & 1 deletion src/cargo/util/auth/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Registry authentication support.

use crate::{
core::features::cargo_docs_link,
sources::CRATES_IO_REGISTRY,
util::{config::ConfigKey, CanonicalUrl, CargoResult, Config, IntoUrl},
};
Expand Down Expand Up @@ -219,7 +220,8 @@ fn credential_provider(
if !global_provider_defined && require_cred_provider_config {
bail!(
"authenticated registries require a credential-provider to be configured\n\
see https://doc.rust-lang.org/cargo/reference/registry-authentication.html for details"
see {} for details",
cargo_docs_link("reference/registry-authentication.html")
);
}
Ok(global_providers)
Expand Down