Skip to content

Commit eb0bb74

Browse files
committed
don't replace a missing version with unknown
1 parent fa7e6a4 commit eb0bb74

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/crates/mod.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ impl TryFrom<&'_ PackageId> for Crate {
161161
name: package_id.name().to_string(),
162162
version: package_id
163163
.version()
164-
.map(|version| version.to_string())
165-
.unwrap_or_else(|| String::from("unknown")),
164+
.ok_or_else(|| anyhow!("missing version for registry crate"))?
165+
.to_string(),
166166
}))
167167
}
168168
Some(SourceKind::Directory) => {
@@ -173,8 +173,8 @@ impl TryFrom<&'_ PackageId> for Crate {
173173
name: package_id.name().to_string(),
174174
version: package_id
175175
.version()
176-
.map(|version| version.to_string())
177-
.unwrap_or_else(|| String::from("unknown")),
176+
.ok_or_else(|| anyhow!("missing version for registry crate"))?
177+
.to_string(),
178178
})),
179179
Some(url) => match url.scheme() {
180180
"http" | "https" | "git" | "ssh" => {
@@ -387,9 +387,13 @@ mod tests {
387387
"file:///path/to/my/project/foo" => Crate::Path("/path/to/my/project/foo".to_string()),
388388
"file:///path/to/my/project/foo#1.1.8" => Crate::Path("/path/to/my/project/foo".to_string()),
389389
"path+file:///path/to/my/project/foo#1.1.8" => Crate::Path("/path/to/my/project/foo".to_string()),
390-
391-
"invalid" => Crate::Registry(RegistryCrate{ name: "invalid".to_string(), version: "unknown".to_string() }),
392390
}
391+
392+
// while `invalid` is a valid package name it is missing a version
393+
assert!(Crate::try_from(&PackageId {
394+
repr: "invalid".to_string()
395+
})
396+
.is_err());
393397
}
394398

395399
#[test]

0 commit comments

Comments
 (0)