From 432b29b3503677099f67f6218bf0878cccfd8745 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 12 Aug 2026 11:10:07 -0500 Subject: [PATCH 1/2] Fix formatting of invalid version bump errors --- crates/uv-cli/src/lib.rs | 6 ++-- crates/uv/tests/it/version.rs | 63 +++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index 6ae2e6c387a..4c365ebebea 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -835,19 +835,19 @@ impl TypedValueParser for VersionBumpSpecValueParser { fn parse_ref( &self, - _cmd: &clap::Command, + command: &clap::Command, _arg: Option<&clap::Arg>, value: &std::ffi::OsStr, ) -> Result { let raw = value.to_str().ok_or_else(|| { - clap::Error::raw( + command.clone().error( ErrorKind::InvalidUtf8, "`--bump` values must be valid UTF-8", ) })?; VersionBumpSpec::from_str(raw) - .map_err(|message| clap::Error::raw(ErrorKind::InvalidValue, message)) + .map_err(|message| command.clone().error(ErrorKind::InvalidValue, message)) } fn possible_values(&self) -> Option + '_>> { diff --git a/crates/uv/tests/it/version.rs b/crates/uv/tests/it/version.rs index 123cf19be50..b80e2ff043c 100644 --- a/crates/uv/tests/it/version.rs +++ b/crates/uv/tests/it/version.rs @@ -1323,6 +1323,57 @@ requires-python = ">=3.12" Ok(()) } +#[test] +fn bump_invalid_component_fails() -> Result<()> { + let context = uv_test::test_context!("3.12"); + + context + .temp_dir + .child("pyproject.toml") + .write_str(indoc! {r#" + [project] + name = "myproject" + version = "1.2.3" + requires-python = ">=3.12" + "#})?; + + let output = uv_snapshot!(context.filters(), context.version() + .arg("--bump").arg("foo"), @" + exit_code: 2 (failure) + ----- stderr ----- + error: invalid bump component `foo` + + Usage: uv version [OPTIONS] [VALUE] + + For more information, try '--help'. + "); + + assert!(output.stderr.ends_with(b"\n")); + + Ok(()) +} + +#[test] +fn bump_invalid_component_color() -> Result<()> { + let context = uv_test::test_context!("3.12"); + + let output = context + .version() + .arg("--bump") + .arg("foo") + .env_remove(EnvVars::NO_COLOR) + .env(EnvVars::CLICOLOR_FORCE, "1") + .output()?; + + assert_eq!(output.status.code(), Some(2)); + assert_snapshot!( + format!("{:?}", String::from_utf8_lossy(&output.stderr)), + @r#""\u{1b}[1m\u{1b}[31merror:\u{1b}[0m invalid bump component `foo`\n\n\u{1b}[1m\u{1b}[32mUsage:\u{1b}[0m \u{1b}[1m\u{1b}[36muv version\u{1b}[0m \u{1b}[36m[OPTIONS]\u{1b}[0m \u{1b}[36m[VALUE]\u{1b}[0m\n\nFor more information, try '\u{1b}[1m\u{1b}[36m--help\u{1b}[0m'.\n""# + ); + + Ok(()) +} + #[test] fn bump_stable_with_value_fails() -> Result<()> { let context = uv_test::test_context!("3.12"); @@ -1342,6 +1393,10 @@ requires-python = ">=3.12" exit_code: 2 (failure) ----- stderr ----- error: `--bump stable` does not accept a value + + Usage: uv version [OPTIONS] [VALUE] + + For more information, try '--help'. "); Ok(()) } @@ -1365,6 +1420,10 @@ requires-python = ">=3.12" exit_code: 2 (failure) ----- stderr ----- error: `--bump` values cannot be empty + + Usage: uv version [OPTIONS] [VALUE] + + For more information, try '--help'. "); Ok(()) } @@ -1388,6 +1447,10 @@ requires-python = ">=3.12" exit_code: 2 (failure) ----- stderr ----- error: invalid numeric value `foo` for `--bump dev` + + Usage: uv version [OPTIONS] [VALUE] + + For more information, try '--help'. "); Ok(()) } From c8b6093cebdd96b590ddc0b58dc82b042783e68e Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Thu, 13 Aug 2026 09:51:29 -0500 Subject: [PATCH 2/2] Normalize Windows executable in version bump snapshot --- crates/uv/tests/it/version.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/uv/tests/it/version.rs b/crates/uv/tests/it/version.rs index b80e2ff043c..0a074da01ba 100644 --- a/crates/uv/tests/it/version.rs +++ b/crates/uv/tests/it/version.rs @@ -5,7 +5,7 @@ use indoc::indoc; use insta::assert_snapshot; use uv_static::EnvVars; -use uv_test::uv_snapshot; +use uv_test::{apply_filters, uv_snapshot}; // Print the version #[test] @@ -1366,8 +1366,12 @@ fn bump_invalid_component_color() -> Result<()> { .output()?; assert_eq!(output.status.code(), Some(2)); + let stderr = apply_filters( + String::from_utf8_lossy(&output.stderr).into_owned(), + context.filters(), + ); assert_snapshot!( - format!("{:?}", String::from_utf8_lossy(&output.stderr)), + format!("{stderr:?}"), @r#""\u{1b}[1m\u{1b}[31merror:\u{1b}[0m invalid bump component `foo`\n\n\u{1b}[1m\u{1b}[32mUsage:\u{1b}[0m \u{1b}[1m\u{1b}[36muv version\u{1b}[0m \u{1b}[36m[OPTIONS]\u{1b}[0m \u{1b}[36m[VALUE]\u{1b}[0m\n\nFor more information, try '\u{1b}[1m\u{1b}[36m--help\u{1b}[0m'.\n""# );