Skip to content

Commit edd399d

Browse files
committed
Use consistent formatting for build system errors
1 parent 8c8a1f0 commit edd399d

File tree

9 files changed

+127
-99
lines changed

9 files changed

+127
-99
lines changed

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

+64-35
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,22 @@ impl Display for MissingHeaderCause {
108108
{
109109
write!(
110110
f,
111-
"This error likely indicates that you need to install a library that provides \"{header}\" for {package_name}@{package_version}",
111+
"This error likely indicates that you need to install a library that provides \"{}\" for `{}`",
112+
header.cyan(),
113+
format!("{package_name}@{package_version}").cyan(),
112114
)
113115
} else if let Some(version_id) = &self.version_id {
114116
write!(
115117
f,
116-
"This error likely indicates that you need to install a library that provides \"{header}\" for {version_id}",
118+
"This error likely indicates that you need to install a library that provides \"{}\" for `{}`",
119+
header.cyan(),
120+
version_id.cyan(),
117121
)
118122
} else {
119123
write!(
120124
f,
121-
"This error likely indicates that you need to install a library that provides \"{header}\"",
125+
"This error likely indicates that you need to install a library that provides \"{}\"",
126+
header.cyan(),
122127
)
123128
}
124129
}
@@ -128,17 +133,25 @@ impl Display for MissingHeaderCause {
128133
{
129134
write!(
130135
f,
131-
"This error likely indicates that you need to install the library that provides a shared library for {library} for {package_name}@{package_version} (e.g., lib{library}-dev)",
136+
"This error likely indicates that you need to install the library that provides a shared library for `{}` for `{}` (e.g., `{}`)",
137+
library.cyan(),
138+
format!("{package_name}@{package_version}").cyan(),
139+
format!("lib{library}-dev").cyan(),
132140
)
133141
} else if let Some(version_id) = &self.version_id {
134142
write!(
135143
f,
136-
"This error likely indicates that you need to install the library that provides a shared library for {library} for {version_id} (e.g., lib{library}-dev)",
144+
"This error likely indicates that you need to install the library that provides a shared library for `{}` for `{}` (e.g., `{}`)",
145+
library.cyan(),
146+
version_id.cyan(),
147+
format!("lib{library}-dev").cyan(),
137148
)
138149
} else {
139150
write!(
140151
f,
141-
"This error likely indicates that you need to install the library that provides a shared library for {library} (e.g., lib{library}-dev)",
152+
"This error likely indicates that you need to install the library that provides a shared library for `{}` (e.g., `{}`)",
153+
library.cyan(),
154+
format!("lib{library}-dev").cyan(),
142155
)
143156
}
144157
}
@@ -148,17 +161,36 @@ impl Display for MissingHeaderCause {
148161
{
149162
write!(
150163
f,
151-
"This error likely indicates that {package_name}@{package_version} depends on {package}, but doesn't declare it as a build dependency. If {package_name} is a first-party package, consider adding {package} to its `build-system.requires`. Otherwise, `uv pip install {package}` into the environment and re-run with `--no-build-isolation`."
164+
"This error likely indicates that `{}` depends on `{}`, but doesn't declare it as a build dependency. If `{}` is a first-party package, consider adding `{}` to its `{}`. Otherwise, `{}` into the environment and re-run with `{}`.",
165+
format!("{package_name}@{package_version}").cyan(),
166+
package.cyan(),
167+
package_name.cyan(),
168+
package.cyan(),
169+
"build-system.requires".green(),
170+
format!("uv pip install {package}").green(),
171+
"--no-build-isolation".green(),
152172
)
153173
} else if let Some(version_id) = &self.version_id {
154174
write!(
155175
f,
156-
"This error likely indicates that {version_id} depends on {package}, but doesn't declare it as a build dependency. If {version_id} is a first-party package, consider adding {package} to its `build-system.requires`. Otherwise, `uv pip install {package}` into the environment and re-run with `--no-build-isolation`.",
176+
"This error likely indicates that `{}` depends on `{}`, but doesn't declare it as a build dependency. If `{}` is a first-party package, consider adding `{}` to its `{}`. Otherwise, `{}` into the environment and re-run with `{}`.",
177+
version_id.cyan(),
178+
package.cyan(),
179+
version_id.cyan(),
180+
package.cyan(),
181+
"build-system.requires".green(),
182+
format!("uv pip install {package}").green(),
183+
"--no-build-isolation".green(),
157184
)
158185
} else {
159186
write!(
160187
f,
161-
"This error likely indicates that a package depends on {package}, but doesn't declare it as a build dependency. If the package is a first-party package, consider adding {package} to its `build-system.requires`. Otherwise, `uv pip install {package}` into the environment and re-run with `--no-build-isolation`.",
188+
"This error likely indicates that a package depends on `{}`, but doesn't declare it as a build dependency. If the package is a first-party package, consider adding `{}` to its `{}`. Otherwise, `{}` into the environment and re-run with `{}`.",
189+
package.cyan(),
190+
package.cyan(),
191+
"build-system.requires".green(),
192+
format!("uv pip install {package}").green(),
193+
"--no-build-isolation".green(),
162194
)
163195
}
164196
}
@@ -168,12 +200,18 @@ impl Display for MissingHeaderCause {
168200
{
169201
write!(
170202
f,
171-
"{package} was removed from the standard library in Python {version}. Consider adding a constraint (like `{package_name} >{package_version}`) to avoid building a version of {package_name} that depends on {package}.",
203+
"`{}` was removed from the standard library in Python {version}. Consider adding a constraint (like `{}`) to avoid building a version of `{}` that depends on `{}`.",
204+
package.cyan(),
205+
format!("{package_name} >{package_version}").green(),
206+
package_name.cyan(),
207+
package.cyan(),
172208
)
173209
} else {
174210
write!(
175211
f,
176-
"{package} was removed from the standard library in Python {version}. Consider adding a constraint to avoid building a package-version that depends on {package}.",
212+
"`{}` was removed from the standard library in Python {version}. Consider adding a constraint to avoid building a package that depends on `{}`.",
213+
package.cyan(),
214+
package.cyan(),
177215
)
178216
}
179217
}
@@ -219,29 +257,28 @@ pub struct MissingHeaderError {
219257
exit_code: ExitStatus,
220258
stdout: Vec<String>,
221259
stderr: Vec<String>,
222-
#[source]
223260
cause: MissingHeaderCause,
224261
}
225262

226263
impl Display for MissingHeaderError {
227264
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
228265
write!(f, "{} ({})", self.message, self.exit_code)?;
229266

230-
let mut non_empty = false;
231-
232267
if self.stdout.iter().any(|line| !line.trim().is_empty()) {
233268
write!(f, "\n\n{}\n{}", "[stdout]".red(), self.stdout.join("\n"))?;
234-
non_empty = true;
235269
}
236270

237271
if self.stderr.iter().any(|line| !line.trim().is_empty()) {
238272
write!(f, "\n\n{}\n{}", "[stderr]".red(), self.stderr.join("\n"))?;
239-
non_empty = true;
240273
}
241274

242-
if non_empty {
243-
writeln!(f)?;
244-
}
275+
write!(
276+
f,
277+
"\n\n{}{} {}",
278+
"hint".bold().cyan(),
279+
":".bold(),
280+
self.cause
281+
)?;
245282

246283
Ok(())
247284
}
@@ -401,11 +438,9 @@ mod test {
401438
| ^~~~~~~~~~~~~~~~~~~
402439
compilation terminated.
403440
error: command '/usr/bin/gcc' failed with exit code 1
441+
442+
hint: This error likely indicates that you need to install a library that provides "graphviz/cgraph.h" for `pygraphviz-1.11`
404443
"###);
405-
insta::assert_snapshot!(
406-
std::error::Error::source(&err).unwrap(),
407-
@r###"This error likely indicates that you need to install a library that provides "graphviz/cgraph.h" for pygraphviz-1.11"###
408-
);
409444
}
410445

411446
#[test]
@@ -447,11 +482,9 @@ mod test {
447482
/usr/bin/ld: cannot find -lncurses: No such file or directory
448483
collect2: error: ld returned 1 exit status
449484
error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
485+
486+
hint: This error likely indicates that you need to install the library that provides a shared library for `ncurses` for `pygraphviz-1.11` (e.g., `libncurses-dev`)
450487
"###);
451-
insta::assert_snapshot!(
452-
std::error::Error::source(&err).unwrap(),
453-
@"This error likely indicates that you need to install the library that provides a shared library for ncurses for pygraphviz-1.11 (e.g., libncurses-dev)"
454-
);
455488
}
456489

457490
#[test]
@@ -495,11 +528,9 @@ mod test {
495528
or: setup.py cmd --help
496529
497530
error: invalid command 'bdist_wheel'
531+
532+
hint: This error likely indicates that `pygraphviz-1.11` depends on `wheel`, but doesn't declare it as a build dependency. If `pygraphviz-1.11` is a first-party package, consider adding `wheel` to its `build-system.requires`. Otherwise, `uv pip install wheel` into the environment and re-run with `--no-build-isolation`.
498533
"###);
499-
insta::assert_snapshot!(
500-
std::error::Error::source(&err).unwrap(),
501-
@"This error likely indicates that pygraphviz-1.11 depends on wheel, but doesn't declare it as a build dependency. If pygraphviz-1.11 is a first-party package, consider adding wheel to its `build-system.requires`. Otherwise, `uv pip install wheel` into the environment and re-run with `--no-build-isolation`."
502-
);
503534
}
504535

505536
#[test]
@@ -536,10 +567,8 @@ mod test {
536567
[stderr]
537568
import distutils.core
538569
ModuleNotFoundError: No module named 'distutils'
570+
571+
hint: `distutils` was removed from the standard library in Python 3.12. Consider adding a constraint (like `pygraphviz >1.11`) to avoid building a version of `pygraphviz` that depends on `distutils`.
539572
"###);
540-
insta::assert_snapshot!(
541-
std::error::Error::source(&err).unwrap(),
542-
@"distutils was removed from the standard library in Python 3.12. Consider adding a constraint (like `pygraphviz >1.11`) to avoid building a version of pygraphviz that depends on distutils."
543-
);
544573
}
545574
}

0 commit comments

Comments
 (0)