From 57622d793935a662b5f14ca728a2989c14833d37 Mon Sep 17 00:00:00 2001 From: Tor Hovland <55164+torhovland@users.noreply.github.com> Date: Sun, 21 Jul 2024 10:00:07 +0200 Subject: [PATCH] fix: Improved error message when update --breaking invalid spec. --- src/cargo/ops/cargo_update.rs | 6 +++++- tests/testsuite/update.rs | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cargo/ops/cargo_update.rs b/src/cargo/ops/cargo_update.rs index c3d367311e1..ab78988e53d 100644 --- a/src/cargo/ops/cargo_update.rs +++ b/src/cargo/ops/cargo_update.rs @@ -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; @@ -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::, _>>()?; // Updates often require a lot of modifications to the registry, so ensure diff --git a/tests/testsuite/update.rs b/tests/testsuite/update.rs index 1e74e32f93c..f27fd68881a 100644 --- a/tests/testsuite/update.rs +++ b/tests/testsuite/update.rs @@ -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();