Skip to content

Commit 7e09951

Browse files
committed
install: Added error message for when v is prefixed with version
1 parent 681597f commit 7e09951

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/bin/cargo/commands/install.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ fn parse_semver_flag(v: &str) -> CargoResult<VersionReq> {
286286
.next()
287287
.ok_or_else(|| format_err!("no version provided for the `--version` flag"))?;
288288

289+
if let Some(stripped) = v.strip_prefix("v") {
290+
bail!(
291+
"the version provided, `{v}` is not a valid SemVer requirement\n\n\
292+
help: try changing the version to `{stripped}`",
293+
)
294+
}
289295
let is_req = "<>=^~".contains(first) || v.contains('*');
290296
if is_req {
291297
match v.parse::<VersionReq>() {

tests/testsuite/install.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2906,7 +2906,9 @@ fn prefixed_v_in_version() {
29062906
cargo_process("install foo@v0.0.1")
29072907
.with_status(1)
29082908
.with_stderr_data(str![[r#"
2909-
[ERROR] invalid value 'foo@v0.0.1' for '[CRATE[@<VER>]]...': unexpected character 'v' while parsing major version number
2909+
[ERROR] invalid value 'foo@v0.0.1' for '[CRATE[@<VER>]]...': the version provided, `v0.0.1` is not a valid SemVer requirement
2910+
2911+
[HELP] try changing the version to `0.0.1`
29102912
29112913
For more information, try '--help'.
29122914

0 commit comments

Comments
 (0)