Skip to content
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
4 changes: 0 additions & 4 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 6 additions & 3 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ pub fn registry_url(manifest_path: &Path, registry: Option<&str>) -> CargoResult
registries: &mut HashMap<String, Source>,
path: impl AsRef<Path>,
) -> 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::<CargoConfig>(&content).map_err(|_| invalid_cargo_config())?;
let config = toml::from_str::<CargoConfig>(&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,
Expand Down Expand Up @@ -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(&registry_url)
.with_context(|| anyhow::format_err!("invalid `registry` field"))?;

Ok(registry_url)
}
Expand Down