mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +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.
|
/// Gets the index for a registry.
|
||||||
pub fn get_registry_index(&self, registry: &str) -> CargoResult<Url> {
|
pub fn get_registry_index(&self, registry: &str) -> CargoResult<Url> {
|
||||||
validate_package_name(registry, "registry name", "")?;
|
validate_package_name(registry, "registry name", "")?;
|
||||||
Ok(
|
if let Some(index) = self.get_string(&format!("registries.{}.index", registry))? {
|
||||||
match self.get_string(&format!("registries.{}.index", registry))? {
|
self.resolve_registry_index(&index).chain_err(|| {
|
||||||
Some(index) => self.resolve_registry_index(index)?,
|
format!(
|
||||||
None => bail!("No index found for registry: `{}`", registry),
|
"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.
|
/// Returns an error if `registry.index` is set.
|
||||||
@ -1027,7 +1031,8 @@ impl Config {
|
|||||||
Ok(())
|
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
|
let base = index
|
||||||
.definition
|
.definition
|
||||||
.root(self)
|
.root(self)
|
||||||
@ -1036,7 +1041,7 @@ impl Config {
|
|||||||
let _parsed = index.val.into_url()?;
|
let _parsed = index.val.into_url()?;
|
||||||
let url = index.val.into_url_with_base(Some(&*base))?;
|
let url = index.val.into_url_with_base(Some(&*base))?;
|
||||||
if url.password().is_some() {
|
if url.password().is_some() {
|
||||||
bail!("Registry URLs may not contain passwords");
|
bail!("registry URLs may not contain passwords");
|
||||||
}
|
}
|
||||||
Ok(url)
|
Ok(url)
|
||||||
}
|
}
|
||||||
|
@ -548,7 +548,14 @@ fn passwords_in_registries_index_url_forbidden() {
|
|||||||
|
|
||||||
p.cargo("publish --registry alternative")
|
p.cargo("publish --registry alternative")
|
||||||
.with_status(101)
|
.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();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1240,6 +1247,9 @@ fn registries_index_relative_path_not_allowed() {
|
|||||||
"\
|
"\
|
||||||
error: failed to parse manifest at `{root}/foo/Cargo.toml`
|
error: failed to parse manifest at `{root}/foo/Cargo.toml`
|
||||||
|
|
||||||
|
Caused by:
|
||||||
|
invalid index URL for registry `relative` defined in [..]/.cargo/config
|
||||||
|
|
||||||
Caused by:
|
Caused by:
|
||||||
invalid url `alternative-registry`: relative URL without a base
|
invalid url `alternative-registry`: relative URL without a base
|
||||||
",
|
",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user