@@ -161,8 +161,8 @@ impl TryFrom<&'_ PackageId> for Crate {
161
161
name : package_id. name ( ) . to_string ( ) ,
162
162
version : package_id
163
163
. 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 ( ) ,
166
166
} ) )
167
167
}
168
168
Some ( SourceKind :: Directory ) => {
@@ -173,8 +173,8 @@ impl TryFrom<&'_ PackageId> for Crate {
173
173
name : package_id. name ( ) . to_string ( ) ,
174
174
version : package_id
175
175
. 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 ( ) ,
178
178
} ) ) ,
179
179
Some ( url) => match url. scheme ( ) {
180
180
"http" | "https" | "git" | "ssh" => {
@@ -387,9 +387,13 @@ mod tests {
387
387
"file:///path/to/my/project/foo" => Crate :: Path ( "/path/to/my/project/foo" . to_string( ) ) ,
388
388
"file:///path/to/my/project/foo#1.1.8" => Crate :: Path ( "/path/to/my/project/foo" . to_string( ) ) ,
389
389
"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( ) } ) ,
392
390
}
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( ) ) ;
393
397
}
394
398
395
399
#[ test]
0 commit comments