Skip to content

Commit 2ba61b9

Browse files
committed
update: Added error message for when v is prefixed with version
1 parent ef3e28d commit 2ba61b9

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/cargo/core/source_id.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,16 @@ impl SourceId {
523523
version: semver::Version,
524524
precise: &str,
525525
) -> CargoResult<SourceId> {
526-
let precise = semver::Version::parse(precise)
527-
.with_context(|| format!("invalid version format for precise version `{precise}`"))?;
526+
let precise = semver::Version::parse(precise).with_context(|| {
527+
if let Some(stripped) = precise.strip_prefix("v") {
528+
return format!(
529+
"the version provided, `{precise}` is not a \
530+
valid SemVer version\n\n\
531+
help: try changing the version to `{stripped}`",
532+
);
533+
}
534+
format!("invalid version format for precise version `{precise}`")
535+
})?;
528536

529537
Ok(SourceId::wrap(SourceIdInner {
530538
precise: Some(Precise::Updated {

tests/testsuite/update.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2737,7 +2737,9 @@ fn prefixed_v_in_version() {
27372737
p.cargo("update bar --precise v1.0.1")
27382738
.with_status(101)
27392739
.with_stderr_data(str![[r#"
2740-
[ERROR] invalid version format for precise version `v1.0.1`
2740+
[ERROR] the version provided, `v1.0.1` is not a valid SemVer version
2741+
2742+
[HELP] try changing the version to `1.0.1`
27412743
27422744
Caused by:
27432745
unexpected character 'v' while parsing major version number

0 commit comments

Comments
 (0)