Skip to content

Commit aaf2f0e

Browse files
committed
Improve error message copy for failed builds
1 parent 6c7f8bb commit aaf2f0e

File tree

8 files changed

+30
-36
lines changed

8 files changed

+30
-36
lines changed

crates/uv-build-frontend/src/error.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,23 @@ pub enum Error {
6363
InvalidPyprojectTomlSchema(#[from] toml_edit::de::Error),
6464
#[error("Editable installs with setup.py legacy builds are unsupported, please specify a build backend in pyproject.toml")]
6565
EditableSetupPy,
66+
#[error("Failed to resolve requirements from {0}")]
67+
RequirementsResolve(&'static str, #[source] anyhow::Error),
6668
#[error("Failed to install requirements from {0}")]
6769
RequirementsInstall(&'static str, #[source] anyhow::Error),
6870
#[error("Failed to create temporary virtualenv")]
6971
Virtualenv(#[from] uv_virtualenv::Error),
7072
#[error("Failed to run `{0}`")]
7173
CommandFailed(PathBuf, #[source] io::Error),
72-
#[error("{message} with {exit_code}\n--- stdout:\n{stdout}\n--- stderr:\n{stderr}\n---")]
74+
#[error("{message} ({exit_code})\n--- stdout:\n{stdout}\n--- stderr:\n{stderr}\n---")]
7375
BuildBackendOutput {
7476
message: String,
7577
exit_code: ExitStatus,
7678
stdout: String,
7779
stderr: String,
7880
},
7981
/// Nudge the user towards installing the missing dev library
80-
#[error("{message} with {exit_code}\n--- stdout:\n{stdout}\n--- stderr:\n{stderr}\n---")]
82+
#[error("{message} ({exit_code})\n--- stdout:\n{stdout}\n--- stderr:\n{stderr}\n---")]
8183
MissingHeaderOutput {
8284
message: String,
8385
exit_code: ExitStatus,
@@ -86,12 +88,12 @@ pub enum Error {
8688
#[source]
8789
missing_header_cause: MissingHeaderCause,
8890
},
89-
#[error("{message} with {exit_code}")]
91+
#[error("{message} ({exit_code})")]
9092
BuildBackend {
9193
message: String,
9294
exit_code: ExitStatus,
9395
},
94-
#[error("{message} with {exit_code}")]
96+
#[error("{message} ({exit_code})")]
9597
MissingHeader {
9698
message: String,
9799
exit_code: ExitStatus,

crates/uv-build-frontend/src/lib.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,7 @@ impl SourceBuild {
310310
build_context
311311
.install(&resolved_requirements, &venv)
312312
.await
313-
.map_err(|err| {
314-
Error::RequirementsInstall("`build-system.requires` (install)", err)
315-
})?;
313+
.map_err(|err| Error::RequirementsInstall("`build-system.requires`", err))?;
316314
} else {
317315
debug!("Proceeding without build isolation");
318316
}
@@ -407,19 +405,15 @@ impl SourceBuild {
407405
let resolved_requirements = build_context
408406
.resolve(&default_backend.requirements)
409407
.await
410-
.map_err(|err| {
411-
Error::RequirementsInstall("`setup.py` build (resolve)", err)
412-
})?;
408+
.map_err(|err| Error::RequirementsResolve("`setup.py` build", err))?;
413409
*resolution = Some(resolved_requirements.clone());
414410
resolved_requirements
415411
}
416412
} else {
417413
build_context
418414
.resolve(&pep517_backend.requirements)
419415
.await
420-
.map_err(|err| {
421-
Error::RequirementsInstall("`build-system.requires` (resolve)", err)
422-
})?
416+
.map_err(|err| Error::RequirementsResolve("`build-system.requires`", err))?
423417
},
424418
)
425419
}
@@ -808,7 +802,7 @@ async fn create_pep517_build_environment(
808802
.await?;
809803
if !output.status.success() {
810804
return Err(Error::from_command_output(
811-
format!("Build backend failed to determine extra requires with `build_{build_kind}()`"),
805+
format!("Build backend failed to determine requirements with `build_{build_kind}()`"),
812806
&output,
813807
level,
814808
package_name,
@@ -821,7 +815,7 @@ async fn create_pep517_build_environment(
821815
let contents = fs_err::read(&outfile).map_err(|err| {
822816
Error::from_command_output(
823817
format!(
824-
"Build backend failed to read extra requires from `get_requires_for_build_{build_kind}`: {err}"
818+
"Build backend failed to read requirements from `get_requires_for_build_{build_kind}`: {err}"
825819
),
826820
&output,
827821
level,
@@ -835,7 +829,7 @@ async fn create_pep517_build_environment(
835829
let extra_requires: Vec<pep508_rs::Requirement<VerbatimParsedUrl>> = serde_json::from_slice::<Vec<pep508_rs::Requirement<VerbatimParsedUrl>>>(&contents).map_err(|err| {
836830
Error::from_command_output(
837831
format!(
838-
"Build backend failed to return extra requires with `get_requires_for_build_{build_kind}`: {err}"
832+
"Build backend failed to return requirements from `get_requires_for_build_{build_kind}`: {err}"
839833
),
840834
&output,
841835
level,
@@ -864,12 +858,12 @@ async fn create_pep517_build_environment(
864858
let resolution = build_context
865859
.resolve(&requirements)
866860
.await
867-
.map_err(|err| Error::RequirementsInstall("`build-system.requires` (resolve)", err))?;
861+
.map_err(|err| Error::RequirementsResolve("`build-system.requires`", err))?;
868862

869863
build_context
870864
.install(&resolution, venv)
871865
.await
872-
.map_err(|err| Error::RequirementsInstall("`build-system.requires` (install)", err))?;
866+
.map_err(|err| Error::RequirementsInstall("`build-system.requires`", err))?;
873867
}
874868

875869
Ok(())

crates/uv/tests/build.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ fn fail() -> Result<()> {
888888
File "<string>", line 2
889889
from setuptools import setup
890890
IndentationError: unexpected indent
891-
error: Build backend failed to determine extra requires with `build_sdist()` with exit status: 1
891+
error: Build backend failed to determine requirements with `build_sdist()` (exit status: 1)
892892
"###);
893893

894894
Ok(())
@@ -1328,7 +1328,7 @@ fn build_all_with_failure() -> Result<()> {
13281328
[PKG] Building wheel from source distribution...
13291329
[PKG] Building wheel from source distribution...
13301330
Successfully built dist/member_a-0.1.0.tar.gz and dist/member_a-0.1.0-py3-none-any.whl
1331-
[PKG] error: Build backend failed to determine extra requires with `build_sdist()` with exit status: 1
1331+
[PKG] error: Build backend failed to determine requirements with `build_sdist()` (exit status: 1)
13321332
Successfully built dist/project-0.1.0.tar.gz and dist/project-0.1.0-py3-none-any.whl
13331333
"###);
13341334

@@ -1397,7 +1397,7 @@ fn build_constraints() -> Result<()> {
13971397
13981398
----- stderr -----
13991399
Building source distribution...
1400-
error: Failed to install requirements from `build-system.requires` (resolve)
1400+
error: Failed to resolve requirements from `build-system.requires`
14011401
Caused by: No solution found when resolving: `setuptools>=42`
14021402
Caused by: Because you require setuptools>=42 and setuptools==0.1.0, we can conclude that your requirements are unsatisfiable.
14031403
"###);
@@ -1551,7 +1551,7 @@ fn sha() -> Result<()> {
15511551
15521552
----- stderr -----
15531553
Building source distribution...
1554-
error: Failed to install requirements from `build-system.requires` (install)
1554+
error: Failed to install requirements from `build-system.requires`
15551555
Caused by: Failed to prepare distributions
15561556
Caused by: Failed to fetch wheel: setuptools==68.2.2
15571557
Caused by: Hash mismatch for `setuptools==68.2.2`

crates/uv/tests/edit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4594,7 +4594,7 @@ fn fail_to_add_revert_project() -> Result<()> {
45944594
Resolved 2 packages in [TIME]
45954595
error: Failed to prepare distributions
45964596
Caused by: Failed to fetch wheel: pytorch==1.0.2
4597-
Caused by: Build backend failed to build wheel through `build_wheel()` with exit status: 1
4597+
Caused by: Build backend failed to build wheel through `build_wheel()` (exit status: 1)
45984598
--- stdout:
45994599
46004600
--- stderr:

crates/uv/tests/pip_compile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11782,7 +11782,7 @@ fn incompatible_build_constraint() -> Result<()> {
1178211782
1178311783
----- stderr -----
1178411784
× Failed to download and build `requests==1.2.0`
11785-
├─▶ Failed to install requirements from `setup.py` build (resolve)
11785+
├─▶ Failed to resolve requirements from `setup.py` build
1178611786
├─▶ No solution found when resolving: `setuptools>=40.8.0`
1178711787
╰─▶ Because you require setuptools>=40.8.0 and setuptools==1, we can conclude that your requirements are unsatisfiable.
1178811788
"###

crates/uv/tests/pip_install.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,9 @@ dependencies = ["flask==1.0.x"]
227227
let requirements_txt = context.temp_dir.child("requirements.txt");
228228
requirements_txt.write_str("./path_dep")?;
229229

230-
let filters = [("exit status", "exit code")]
231-
.into_iter()
230+
let filters = std::iter::once((r"exit code: 1", "exit status: 1"))
232231
.chain(context.filters())
233232
.collect::<Vec<_>>();
234-
235233
uv_snapshot!(filters, context.pip_install()
236234
.arg("-r")
237235
.arg("requirements.txt"), @r###"
@@ -241,7 +239,7 @@ dependencies = ["flask==1.0.x"]
241239
242240
----- stderr -----
243241
error: Failed to build: `project @ file://[TEMP_DIR]/path_dep`
244-
Caused by: Build backend failed to determine extra requires with `build_wheel()` with exit code: 1
242+
Caused by: Build backend failed to determine requirements with `build_wheel()` (exit status: 1)
245243
--- stdout:
246244
configuration error: `project.dependencies[0]` must be pep508
247245
DESCRIPTION:
@@ -3820,7 +3818,7 @@ fn no_build_isolation() -> Result<()> {
38203818
38213819
----- stderr -----
38223820
error: Failed to download and build: `anyio @ https://files.pythonhosted.org/packages/db/4d/3970183622f0330d3c23d9b8a5f52e365e50381fd484d08e3285104333d3/anyio-4.3.0.tar.gz`
3823-
Caused by: Build backend failed to determine metadata through `prepare_metadata_for_build_wheel` with exit status: 1
3821+
Caused by: Build backend failed to determine metadata through `prepare_metadata_for_build_wheel` (exit status: 1)
38243822
--- stdout:
38253823
38263824
--- stderr:
@@ -3890,7 +3888,7 @@ fn respect_no_build_isolation_env_var() -> Result<()> {
38903888
38913889
----- stderr -----
38923890
error: Failed to download and build: `anyio @ https://files.pythonhosted.org/packages/db/4d/3970183622f0330d3c23d9b8a5f52e365e50381fd484d08e3285104333d3/anyio-4.3.0.tar.gz`
3893-
Caused by: Build backend failed to determine metadata through `prepare_metadata_for_build_wheel` with exit status: 1
3891+
Caused by: Build backend failed to determine metadata through `prepare_metadata_for_build_wheel` (exit status: 1)
38943892
--- stdout:
38953893
38963894
--- stderr:
@@ -6759,7 +6757,7 @@ fn incompatible_build_constraint() -> Result<()> {
67596757
67606758
----- stderr -----
67616759
× Failed to download and build `requests==1.2.0`
6762-
├─▶ Failed to install requirements from `setup.py` build (resolve)
6760+
├─▶ Failed to resolve requirements from `setup.py` build
67636761
├─▶ No solution found when resolving: `setuptools>=40.8.0`
67646762
╰─▶ Because you require setuptools>=40.8.0 and setuptools==1, we can conclude that your requirements are unsatisfiable.
67656763
"###
@@ -6835,7 +6833,7 @@ fn install_build_isolation_package() -> Result<()> {
68356833
68366834
----- stderr -----
68376835
error: Failed to download and build: `iniconfig @ https://files.pythonhosted.org/packages/d7/4b/cbd8e699e64a6f16ca3a8220661b5f83792b3017d0f79807cb8708d33913/iniconfig-2.0.0.tar.gz`
6838-
Caused by: Build backend failed to determine metadata through `prepare_metadata_for_build_wheel` with exit status: 1
6836+
Caused by: Build backend failed to determine metadata through `prepare_metadata_for_build_wheel` (exit status: 1)
68396837
--- stdout:
68406838
68416839
--- stderr:
@@ -7096,7 +7094,7 @@ fn sklearn() {
70967094
70977095
----- stderr -----
70987096
× Failed to download and build `sklearn==0.0.post12`
7099-
╰─▶ Build backend failed to determine extra requires with `build_wheel()` with exit status: 1
7097+
╰─▶ Build backend failed to determine requirements with `build_wheel()` (exit status: 1)
71007098
--- stdout:
71017099
71027100
--- stderr:

crates/uv/tests/pip_sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5499,7 +5499,7 @@ fn incompatible_build_constraint() -> Result<()> {
54995499
Resolved 1 package in [TIME]
55005500
error: Failed to prepare distributions
55015501
Caused by: Failed to fetch wheel: requests==1.2.0
5502-
Caused by: Failed to install requirements from `setup.py` build (resolve)
5502+
Caused by: Failed to resolve requirements from `setup.py` build
55035503
Caused by: No solution found when resolving: `setuptools>=40.8.0`
55045504
Caused by: Because you require setuptools>=40.8.0 and setuptools==1, we can conclude that your requirements are unsatisfiable.
55055505
"###

crates/uv/tests/sync.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ fn sync_build_isolation_package() -> Result<()> {
577577
Resolved 2 packages in [TIME]
578578
error: Failed to prepare distributions
579579
Caused by: Failed to fetch wheel: source-distribution @ https://files.pythonhosted.org/packages/10/1f/57aa4cce1b1abf6b433106676e15f9fa2c92ed2bd4cf77c3b50a9e9ac773/source_distribution-0.0.1.tar.gz
580-
Caused by: Build backend failed to build wheel through `build_wheel()` with exit status: 1
580+
Caused by: Build backend failed to build wheel through `build_wheel()` (exit status: 1)
581581
--- stdout:
582582
583583
--- stderr:
@@ -669,7 +669,7 @@ fn sync_build_isolation_extra() -> Result<()> {
669669
Resolved [N] packages in [TIME]
670670
error: Failed to prepare distributions
671671
Caused by: Failed to fetch wheel: source-distribution @ https://files.pythonhosted.org/packages/10/1f/57aa4cce1b1abf6b433106676e15f9fa2c92ed2bd4cf77c3b50a9e9ac773/source_distribution-0.0.1.tar.gz
672-
Caused by: Build backend failed to build wheel through `build_wheel()` with exit status: 1
672+
Caused by: Build backend failed to build wheel through `build_wheel()` (exit status: 1)
673673
--- stdout:
674674
675675
--- stderr:

0 commit comments

Comments
 (0)