From 7dd564d3d09668488c179b02bfe446754e58a5ea Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Thu, 5 Jun 2025 16:48:34 -0500 Subject: [PATCH] Improve `python pin` error messages (#13862) Addresses https://github.com/astral-sh/uv/issues/13854 --- crates/uv/src/commands/python/pin.rs | 5 ++++- crates/uv/tests/it/python_pin.rs | 16 ++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/crates/uv/src/commands/python/pin.rs b/crates/uv/src/commands/python/pin.rs index 5e2b89c18..471f7461e 100644 --- a/crates/uv/src/commands/python/pin.rs +++ b/crates/uv/src/commands/python/pin.rs @@ -60,6 +60,9 @@ pub(crate) async fn pin( if rm { let Some(file) = version_file? else { + if global { + bail!("No global Python pin found"); + } bail!("No Python version file found"); }; fs_err::tokio::remove_file(file.path()).await?; @@ -87,7 +90,7 @@ pub(crate) async fn pin( } return Ok(ExitStatus::Success); } - bail!("No pinned Python version found") + bail!("No Python version file found; specify a version to create one") }; let request = PythonRequest::parse(&request); diff --git a/crates/uv/tests/it/python_pin.rs b/crates/uv/tests/it/python_pin.rs index 6aff28dbf..cf220d6b1 100644 --- a/crates/uv/tests/it/python_pin.rs +++ b/crates/uv/tests/it/python_pin.rs @@ -15,14 +15,14 @@ fn python_pin() { let context: TestContext = TestContext::new_with_versions(&["3.11", "3.12"]); // Without arguments, we attempt to read the current pin (which does not exist yet) - uv_snapshot!(context.filters(), context.python_pin(), @r###" + uv_snapshot!(context.filters(), context.python_pin(), @r" success: false exit_code: 2 ----- stdout ----- ----- stderr ----- - error: No pinned Python version found - "###); + error: No Python version file found; specify a version to create one + "); // Given an argument, we pin to that version uv_snapshot!(context.filters(), context.python_pin().arg("any"), @r###" @@ -209,14 +209,14 @@ fn python_pin_global_if_no_local() -> Result<()> { uv.create_dir_all()?; // Without arguments, we attempt to read the current pin (which does not exist yet) - uv_snapshot!(context.filters(), context.python_pin(), @r###" + uv_snapshot!(context.filters(), context.python_pin(), @r" success: false exit_code: 2 ----- stdout ----- ----- stderr ----- - error: No pinned Python version found - "###); + error: No Python version file found; specify a version to create one + "); // Given an argument, we globally pin to that version uv_snapshot!(context.filters(), context.python_pin().arg("3.11").arg("--global"), @r" @@ -846,7 +846,7 @@ fn python_pin_rm() { ----- stdout ----- ----- stderr ----- - error: No Python version file found + error: No global Python pin found "); // Global does not detect the local pin @@ -857,7 +857,7 @@ fn python_pin_rm() { ----- stdout ----- ----- stderr ----- - error: No Python version file found + error: No global Python pin found "); context