Skip to content

Commit ff9126d

Browse files
committed
Provide some error context for bad registries.foo.index URL.
1 parent 40d566d commit ff9126d

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/cargo/util/config/mod.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -1008,12 +1008,16 @@ impl Config {
10081008
/// Gets the index for a registry.
10091009
pub fn get_registry_index(&self, registry: &str) -> CargoResult<Url> {
10101010
validate_package_name(registry, "registry name", "")?;
1011-
Ok(
1012-
match self.get_string(&format!("registries.{}.index", registry))? {
1013-
Some(index) => self.resolve_registry_index(index)?,
1014-
None => bail!("No index found for registry: `{}`", registry),
1015-
},
1016-
)
1011+
if let Some(index) = self.get_string(&format!("registries.{}.index", registry))? {
1012+
self.resolve_registry_index(&index).chain_err(|| {
1013+
format!(
1014+
"invalid index URL for registry `{}` defined in {}",
1015+
registry, index.definition
1016+
)
1017+
})
1018+
} else {
1019+
bail!("no index found for registry: `{}`", registry);
1020+
}
10171021
}
10181022

10191023
/// Returns an error if `registry.index` is set.
@@ -1027,7 +1031,8 @@ impl Config {
10271031
Ok(())
10281032
}
10291033

1030-
fn resolve_registry_index(&self, index: Value<String>) -> CargoResult<Url> {
1034+
fn resolve_registry_index(&self, index: &Value<String>) -> CargoResult<Url> {
1035+
// This handles relative file: URLs, relative to the config definition.
10311036
let base = index
10321037
.definition
10331038
.root(self)
@@ -1036,7 +1041,7 @@ impl Config {
10361041
let _parsed = index.val.into_url()?;
10371042
let url = index.val.into_url_with_base(Some(&*base))?;
10381043
if url.password().is_some() {
1039-
bail!("Registry URLs may not contain passwords");
1044+
bail!("registry URLs may not contain passwords");
10401045
}
10411046
Ok(url)
10421047
}

tests/testsuite/alt_registry.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,14 @@ fn passwords_in_registries_index_url_forbidden() {
548548

549549
p.cargo("publish --registry alternative")
550550
.with_status(101)
551-
.with_stderr_contains("error: Registry URLs may not contain passwords")
551+
.with_stderr(
552+
"\
553+
error: invalid index URL for registry `alternative` defined in [..]/home/.cargo/config
554+
555+
Caused by:
556+
registry URLs may not contain passwords
557+
",
558+
)
552559
.run();
553560
}
554561

@@ -1240,6 +1247,9 @@ fn registries_index_relative_path_not_allowed() {
12401247
"\
12411248
error: failed to parse manifest at `{root}/foo/Cargo.toml`
12421249
1250+
Caused by:
1251+
invalid index URL for registry `relative` defined in [..]/.cargo/config
1252+
12431253
Caused by:
12441254
invalid url `alternative-registry`: relative URL without a base
12451255
",

0 commit comments

Comments
 (0)