diff --git a/src/errors.rs b/src/errors.rs index fd504a0b64..9b506f1dc2 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -78,10 +78,6 @@ pub(crate) fn non_existent_dependency_err(name: impl Display, table: impl Displa ) } -pub(crate) fn invalid_cargo_config() -> Error { - anyhow::format_err!("Invalid cargo config") -} - pub(crate) fn unsupported_version_req(req: impl Display) -> Error { anyhow::format_err!("Support for modifying {} is currently unsupported", req) } diff --git a/src/registry.rs b/src/registry.rs index f13dfce665..3d53ec36e6 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -13,9 +13,11 @@ pub fn registry_url(manifest_path: &Path, registry: Option<&str>) -> CargoResult registries: &mut HashMap, path: impl AsRef, ) -> CargoResult<()> { + let path = path.as_ref(); // TODO unit test for source replacement let content = std::fs::read_to_string(path)?; - let config = toml::from_str::(&content).map_err(|_| invalid_cargo_config())?; + let config = toml::from_str::(&content) + .with_context(|| anyhow::format_err!("invalid cargo config at {}", path.display()))?; for (key, value) in config.registries { registries.entry(key).or_insert(Source { registry: value.index, @@ -89,8 +91,9 @@ pub fn registry_url(manifest_path: &Path, registry: Option<&str>) -> CargoResult let registry_url = source .registry - .and_then(|x| Url::parse(&x).ok()) - .with_context(invalid_cargo_config)?; + .ok_or_else(|| anyhow::format_err!("missing `registry`"))?; + let registry_url = Url::parse(®istry_url) + .with_context(|| anyhow::format_err!("invalid `registry` field"))?; Ok(registry_url) }