Skip to content

Commit

Permalink
Auto merge of #14279 - tweag:improved-error-message-invalid-spec-upda…
Browse files Browse the repository at this point in the history
…te-breaking, r=weihanglo

Improved error message when `update --breaking` invalid spec.

Improves an error message when trying to do `cargo update --breaking clap@foo`:

```
- [ERROR] expected a version like "1.32"
+ [ERROR] invalid package ID specification: `clap@foo`
+ Caused by:
+   expected a version like "1.32"
```

Related to #12425. Fixes an item [here](#12425 (comment)), as noted [here](#14049 (comment)).
  • Loading branch information
bors committed Jul 22, 2024
2 parents ea14e86 + 57622d7 commit 2d9a335
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/cargo/ops/cargo_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::util::toml_mut::manifest::LocalManifest;
use crate::util::toml_mut::upgrade::upgrade_requirement;
use crate::util::{style, OptVersionReq};
use crate::util::{CargoResult, VersionExt};
use anyhow::Context as _;
use itertools::Itertools;
use semver::{Op, Version, VersionReq};
use std::cmp::Ordering;
Expand Down Expand Up @@ -224,7 +225,10 @@ pub fn upgrade_manifests(

let to_update = to_update
.iter()
.map(|s| PackageIdSpec::parse(s))
.map(|spec| {
PackageIdSpec::parse(spec)
.with_context(|| format!("invalid package ID specification: `{spec}`"))
})
.collect::<Result<Vec<_>, _>>()?;

// Updates often require a lot of modifications to the registry, so ensure
Expand Down
5 changes: 4 additions & 1 deletion tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2263,7 +2263,10 @@ fn update_breaking_spec_version() {
.masquerade_as_nightly_cargo(&["update-breaking"])
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] expected a version like "1.32"
[ERROR] invalid package ID specification: `incompatible@foo`
Caused by:
expected a version like "1.32"
"#]])
.run();
Expand Down

0 comments on commit 2d9a335

Please sign in to comment.