From 93630a8f799baf974f4180548cf59017eb70ca28 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Fri, 22 Aug 2025 15:30:33 +0100 Subject: [PATCH] Include cycle error message in `uv pip` CLI (#15453) ## Summary The use of `format!` was dropping the error chain. Closes https://github.com/astral-sh/uv/issues/15397. --- crates/uv/src/commands/pip/operations.rs | 9 ++-- crates/uv/tests/it/pip_install.rs | 68 ++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/crates/uv/src/commands/pip/operations.rs b/crates/uv/src/commands/pip/operations.rs index 7db3d6a88..58a614f6f 100644 --- a/crates/uv/src/commands/pip/operations.rs +++ b/crates/uv/src/commands/pip/operations.rs @@ -215,11 +215,10 @@ pub(crate) async fn resolve( build_dispatch.workspace_cache(), ) .await - .map_err(|e| { - anyhow!( - "Failed to read dependency groups from: {}\n{}", - pyproject_path.display(), - e + .with_context(|| { + format!( + "Failed to read dependency groups from: {}", + pyproject_path.display() ) })?; diff --git a/crates/uv/tests/it/pip_install.rs b/crates/uv/tests/it/pip_install.rs index af6c4aee8..04e2be938 100644 --- a/crates/uv/tests/it/pip_install.rs +++ b/crates/uv/tests/it/pip_install.rs @@ -9719,6 +9719,74 @@ fn dependency_group() -> Result<()> { Ok(()) } +#[test] +fn recursive_dependency_group() -> Result<()> { + let context = TestContext::new("3.12"); + + // Test a self-referencing group. + let pyproject_toml = context.temp_dir.child("pyproject.toml"); + pyproject_toml.write_str( + r#" + [project] + name = "myproject" + version = "0.1.0" + requires-python = ">=3.12" + + [dependency-groups] + test = [ + { include-group = "test" }, + "requests" + ] + "#, + )?; + + uv_snapshot!(context.filters(), context.pip_install() + .arg("--group").arg("test"), @r" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + error: Failed to read dependency groups from: [TEMP_DIR]/pyproject.toml + Caused by: Project `myproject` has malformed dependency groups + Caused by: Detected a cycle in `dependency-groups`: `test` -> `test` + "); + + // Test mutually recursive groups. + pyproject_toml.write_str( + r#" + [project] + name = "myproject" + version = "0.1.0" + requires-python = ">=3.12" + + [dependency-groups] + test = [ + { include-group = "dev" }, + "requests" + ] + dev = [ + { include-group = "test" }, + "pytest" + ] + "#, + )?; + + uv_snapshot!(context.filters(), context.pip_install() + .arg("--group").arg("test"), @r" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + error: Failed to read dependency groups from: [TEMP_DIR]/pyproject.toml + Caused by: Project `myproject` has malformed dependency groups + Caused by: Detected a cycle in `dependency-groups`: `dev` -> `test` -> `dev` + "); + + Ok(()) +} + #[test] fn virtual_dependency_group() -> Result<()> { // testing basic `uv pip install --group` functionality