File tree Expand file tree Collapse file tree 2 files changed +21
-8
lines changed Expand file tree Collapse file tree 2 files changed +21
-8
lines changed Original file line number Diff line number Diff line change 11use crate :: command_prelude:: * ;
22
3+ use anyhow:: Context ;
34use cargo:: ops;
45use cargo_credential:: Secret ;
56
@@ -60,5 +61,19 @@ fn resolve_crate<'k>(
6061 krate = Some ( k) ;
6162 version = Some ( v) ;
6263 }
64+
65+ if let Some ( version) = version {
66+ semver:: Version :: parse ( version) . with_context ( || {
67+ if let Some ( stripped) = version. strip_prefix ( "v" ) {
68+ return format ! (
69+ "the version provided, `{version}` is not a \
70+ valid SemVer version\n \n \
71+ help: try changing the version to `{stripped}`",
72+ ) ;
73+ }
74+ format ! ( "invalid version `{version}`" )
75+ } ) ?;
76+ }
77+
6378 Ok ( ( krate, version) )
6479}
Original file line number Diff line number Diff line change @@ -237,12 +237,10 @@ fn bad_version() {
237237 . replace_crates_io ( registry. index_url ( ) )
238238 . with_status ( 101 )
239239 . with_stderr_data ( str![ [ r#"
240- [UPDATING] crates.io index
241- [YANK] foo@bar
242- [ERROR] failed to yank from the registry at [ROOTURL]/api
240+ [ERROR] invalid version `bar`
243241
244242Caused by:
245- [37] Couldn't read a file:// file (Couldn't open file [ROOT]/api/api/v1/crates/foo/bar/yank)
243+ unexpected character 'b' while parsing major version number
246244
247245"# ] ] )
248246 . run ( ) ;
@@ -272,12 +270,12 @@ fn prefixed_v_in_version() {
272270 . replace_crates_io ( registry. index_url ( ) )
273271 . with_status ( 101 )
274272 . with_stderr_data ( str![ [ r#"
275- [UPDATING] crates.io index
276- [YANK] bar@v0.0.1
277- [ERROR] failed to yank from the registry at [ROOTURL]/api
273+ [ERROR] the version provided, `v0.0.1` is not a valid SemVer version
274+
275+ [HELP] try changing the version to `0.0.1`
278276
279277Caused by:
280- [37] Couldn't read a file:// file (Couldn't open file [ROOT]/api/api/v1/crates/bar/v0.0.1/yank)
278+ unexpected character 'v' while parsing major version number
281279
282280"# ] ] )
283281 . run ( ) ;
You can’t perform that action at this time.
0 commit comments