Skip to content

Commit abbdb6c

Browse files
authored
Merge pull request #934 from epage/error
fix(upgrade): Improve config error messages
2 parents 1a5dc20 + bbd8d50 commit abbdb6c

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/errors.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ pub(crate) fn non_existent_dependency_err(name: impl Display, table: impl Displa
7878
)
7979
}
8080

81-
pub(crate) fn invalid_cargo_config() -> Error {
82-
anyhow::format_err!("Invalid cargo config")
83-
}
84-
8581
pub(crate) fn unsupported_version_req(req: impl Display) -> Error {
8682
anyhow::format_err!("Support for modifying {} is currently unsupported", req)
8783
}

src/registry.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ pub fn registry_url(manifest_path: &Path, registry: Option<&str>) -> CargoResult
1313
registries: &mut HashMap<String, Source>,
1414
path: impl AsRef<Path>,
1515
) -> CargoResult<()> {
16+
let path = path.as_ref();
1617
// TODO unit test for source replacement
1718
let content = std::fs::read_to_string(path)?;
18-
let config = toml::from_str::<CargoConfig>(&content).map_err(|_| invalid_cargo_config())?;
19+
let config = toml::from_str::<CargoConfig>(&content)
20+
.with_context(|| anyhow::format_err!("invalid cargo config at {}", path.display()))?;
1921
for (key, value) in config.registries {
2022
registries.entry(key).or_insert(Source {
2123
registry: value.index,
@@ -89,8 +91,9 @@ pub fn registry_url(manifest_path: &Path, registry: Option<&str>) -> CargoResult
8991

9092
let registry_url = source
9193
.registry
92-
.and_then(|x| Url::parse(&x).ok())
93-
.with_context(invalid_cargo_config)?;
94+
.ok_or_else(|| anyhow::format_err!("missing `registry`"))?;
95+
let registry_url = Url::parse(&registry_url)
96+
.with_context(|| anyhow::format_err!("invalid `registry` field"))?;
9497

9598
Ok(registry_url)
9699
}

0 commit comments

Comments
 (0)