mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Provide some error context for bad registries.foo.index URL.
This commit is contained in:
parent
40d566d0ae
commit
ff9126d0d2
@ -1008,12 +1008,16 @@ impl Config {
|
||||
/// Gets the index for a registry.
|
||||
pub fn get_registry_index(&self, registry: &str) -> CargoResult<Url> {
|
||||
validate_package_name(registry, "registry name", "")?;
|
||||
Ok(
|
||||
match self.get_string(&format!("registries.{}.index", registry))? {
|
||||
Some(index) => self.resolve_registry_index(index)?,
|
||||
None => bail!("No index found for registry: `{}`", registry),
|
||||
},
|
||||
)
|
||||
if let Some(index) = self.get_string(&format!("registries.{}.index", registry))? {
|
||||
self.resolve_registry_index(&index).chain_err(|| {
|
||||
format!(
|
||||
"invalid index URL for registry `{}` defined in {}",
|
||||
registry, index.definition
|
||||
)
|
||||
})
|
||||
} else {
|
||||
bail!("no index found for registry: `{}`", registry);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns an error if `registry.index` is set.
|
||||
@ -1027,7 +1031,8 @@ impl Config {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn resolve_registry_index(&self, index: Value<String>) -> CargoResult<Url> {
|
||||
fn resolve_registry_index(&self, index: &Value<String>) -> CargoResult<Url> {
|
||||
// This handles relative file: URLs, relative to the config definition.
|
||||
let base = index
|
||||
.definition
|
||||
.root(self)
|
||||
@ -1036,7 +1041,7 @@ impl Config {
|
||||
let _parsed = index.val.into_url()?;
|
||||
let url = index.val.into_url_with_base(Some(&*base))?;
|
||||
if url.password().is_some() {
|
||||
bail!("Registry URLs may not contain passwords");
|
||||
bail!("registry URLs may not contain passwords");
|
||||
}
|
||||
Ok(url)
|
||||
}
|
||||
|
@ -548,7 +548,14 @@ fn passwords_in_registries_index_url_forbidden() {
|
||||
|
||||
p.cargo("publish --registry alternative")
|
||||
.with_status(101)
|
||||
.with_stderr_contains("error: Registry URLs may not contain passwords")
|
||||
.with_stderr(
|
||||
"\
|
||||
error: invalid index URL for registry `alternative` defined in [..]/home/.cargo/config
|
||||
|
||||
Caused by:
|
||||
registry URLs may not contain passwords
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
@ -1240,6 +1247,9 @@ fn registries_index_relative_path_not_allowed() {
|
||||
"\
|
||||
error: failed to parse manifest at `{root}/foo/Cargo.toml`
|
||||
|
||||
Caused by:
|
||||
invalid index URL for registry `relative` defined in [..]/.cargo/config
|
||||
|
||||
Caused by:
|
||||
invalid url `alternative-registry`: relative URL without a base
|
||||
",
|
||||
|
Loading…
x
Reference in New Issue
Block a user