From 798cc7bf3c88d38fd1bfd284a0fd95f70cd65398 Mon Sep 17 00:00:00 2001 From: Alexander Gherm Date: Sun, 11 Aug 2024 23:13:14 +0200 Subject: [PATCH] Make more informative warning message when failed to parse pyproject.toml (#6009) ## Summary Added the actual error message to the warning when uv fails to parse `pyproject.toml`. Resolves https://github.com/astral-sh/uv/issues/5934 ## Test Plan Took the case from the issue: - have `pyproject.toml` which contains ``` [tool.uv] foobar = false ``` - ``` $ uv venv --preview -v ``` - Expect the message that contains the actual problem in the `pyproject.toml` like: ``` warning: Failed to parse `pyproject.toml` during settings discovery: unknown field `foobar`; skipping... ``` --- Cargo.lock | 1 + crates/uv-settings/Cargo.toml | 1 + crates/uv-settings/src/lib.rs | 8 ++++++-- crates/uv/tests/pip_compile.rs | 10 +++++++++- crates/uv/tests/pip_install.rs | 8 +++++++- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 755583cbe..6d5657138 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5127,6 +5127,7 @@ dependencies = [ "pypi-types", "schemars", "serde", + "textwrap", "thiserror", "toml", "tracing", diff --git a/crates/uv-settings/Cargo.toml b/crates/uv-settings/Cargo.toml index b81f8aae2..ea893bde5 100644 --- a/crates/uv-settings/Cargo.toml +++ b/crates/uv-settings/Cargo.toml @@ -31,6 +31,7 @@ dirs-sys = { workspace = true } fs-err = { workspace = true } schemars = { workspace = true, optional = true } serde = { workspace = true } +textwrap = { workspace = true } thiserror = { workspace = true } toml = { workspace = true } tracing = { workspace = true } diff --git a/crates/uv-settings/src/lib.rs b/crates/uv-settings/src/lib.rs index 2aafaf0ab..0edb30e6f 100644 --- a/crates/uv-settings/src/lib.rs +++ b/crates/uv-settings/src/lib.rs @@ -72,9 +72,13 @@ impl FilesystemOptions { Ok(None) => { // Continue traversing the directory tree. } - Err(Error::PyprojectToml(file, _err)) => { + Err(Error::PyprojectToml(file, err)) => { // If we see an invalid `pyproject.toml`, warn but continue. - warn_user!("Failed to parse `{file}` during settings discovery; skipping..."); + warn_user!( + "Failed to parse `{}` during settings discovery:\n{}", + file.cyan(), + textwrap::indent(&err.to_string(), " ") + ); } Err(err) => { // Otherwise, warn and stop. diff --git a/crates/uv/tests/pip_compile.rs b/crates/uv/tests/pip_compile.rs index 53ae853a5..56dd8853b 100644 --- a/crates/uv/tests/pip_compile.rs +++ b/crates/uv/tests/pip_compile.rs @@ -3263,7 +3263,15 @@ fn override_dependency_from_workspace_invalid_syntax() -> Result<()> { ----- stdout ----- ----- stderr ----- - warning: Failed to parse `pyproject.toml` during settings discovery; skipping... + warning: Failed to parse `pyproject.toml` during settings discovery: + TOML parse error at line 9, column 29 + | + 9 | override-dependencies = [ + | ^ + no such comparison operator "=", must be one of ~= == != <= >= < > === + werkzeug=2.3.0 + ^^^^^^ + error: Failed to parse: `pyproject.toml` Caused by: TOML parse error at line 9, column 29 | diff --git a/crates/uv/tests/pip_install.rs b/crates/uv/tests/pip_install.rs index fa7b4716e..0f7fe0af8 100644 --- a/crates/uv/tests/pip_install.rs +++ b/crates/uv/tests/pip_install.rs @@ -125,7 +125,13 @@ fn invalid_pyproject_toml_syntax() -> Result<()> { ----- stdout ----- ----- stderr ----- - warning: Failed to parse `pyproject.toml` during settings discovery; skipping... + warning: Failed to parse `pyproject.toml` during settings discovery: + TOML parse error at line 1, column 5 + | + 1 | 123 - 456 + | ^ + expected `.`, `=` + error: Failed to parse: `pyproject.toml` Caused by: TOML parse error at line 1, column 5 |