Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ uv-dispatch = { version = "0.0.48", path = "crates/uv-dispatch" }
uv-distribution = { version = "0.0.48", path = "crates/uv-distribution" }
uv-distribution-filename = { version = "0.0.48", path = "crates/uv-distribution-filename" }
uv-distribution-types = { version = "0.0.48", path = "crates/uv-distribution-types" }
uv-errors = { version = "0.0.48", path = "crates/uv-errors" }
uv-extract = { version = "0.0.48", path = "crates/uv-extract" }
uv-fastid = { version = "0.0.48", path = "crates/uv-fastid" }
uv-flags = { version = "0.0.48", path = "crates/uv-flags" }
Expand Down
2 changes: 2 additions & 0 deletions crates/uv-build-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ doctest = false

[dependencies]
uv-distribution-filename = { workspace = true }
uv-errors = { workspace = true }
uv-fs = { workspace = true }
uv-globfilter = { workspace = true }
uv-macros = { workspace = true }
Expand Down Expand Up @@ -65,6 +66,7 @@ schemars = ["dep:schemars", "uv-pypi-types/schemars"]
[dev-dependencies]
uv-preview = { workspace = true, features = ["testing"] }

anstream = { workspace = true }
indoc = { workspace = true }
insta = { workspace = true }
regex = { workspace = true }
31 changes: 30 additions & 1 deletion crates/uv-build-backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ pub enum Error {
TarWrite(PathBuf, #[source] io::Error),
}

impl uv_errors::Hint for Error {
fn hints(&self) -> uv_errors::Hints<'_> {
match self {
Self::PortableGlob { source, .. } => uv_errors::Hint::hints(source),
_ => uv_errors::Hints::none(),
}
}
}

/// Dispatcher between writing to a directory, writing to a zip, writing to a `.tar.gz` and
/// listing files.
///
Expand Down Expand Up @@ -476,6 +485,7 @@ mod tests {
use std::pin::Pin;
use tempfile::TempDir;
use uv_distribution_filename::{SourceDistFilename, WheelFilename};
use uv_errors::{ErrorWithHints, Hint};
use uv_fs::{copy_dir_all, relative_to};
use uv_preview::PreviewFeature;

Expand All @@ -487,7 +497,26 @@ mod tests {
let context = iter::successors(std::error::Error::source(&err), |&err| err.source())
.map(|err| format!(" Caused by: {err}"))
.join("\n");
err.to_string() + "\n" + &context
let formatted = err.to_string() + "\n" + &context;
let formatted = ErrorWithHints::new(formatted, err.hints()).to_string();
anstream::adapter::strip_str(&formatted).to_string()
}

#[test]
fn format_err_renders_portable_glob_hints() {
let err = Error::PortableGlob {
field: "tool.uv.build-backend.source-include".to_string(),
source: uv_globfilter::PortableGlobParser::Uv
.parse("**/@test")
.unwrap_err(),
};

assert_snapshot!(format_err(&err), @r#"
Unsupported glob expression in: tool.uv.build-backend.source-include
Caused by: Invalid character `@` at position 3 in glob: `**/@test`

hint: Characters can be escaped with a backslash
"#);
}

/// File listings, generated archives and archive contents for both a build with
Expand Down
1 change: 1 addition & 0 deletions crates/uv-build-frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ uv-cache-key = { workspace = true }
uv-configuration = { workspace = true }
uv-distribution = { workspace = true }
uv-distribution-types = { workspace = true }
uv-errors = { workspace = true }
uv-fs = { workspace = true }
uv-normalize = { workspace = true }
uv-pep440 = { workspace = true }
Expand Down
69 changes: 30 additions & 39 deletions crates/uv-build-frontend/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use regex::Regex;
use thiserror::Error;
use uv_configuration::BuildOutput;
use uv_distribution_types::IsBuildBackendError;
use uv_errors::{Hint, Hints};
use uv_fs::Simplified;
use uv_normalize::PackageName;
use uv_pep440::Version;
Expand Down Expand Up @@ -119,6 +120,20 @@ impl IsBuildBackendError for Error {
}
}

impl Hint for Error {
fn hints(&self) -> Hints<'_> {
match self {
Self::BuildBackend(_) => Hints::from(
"Build failures usually indicate a problem with the package or the build environment",
),
Self::MissingHeader(err) => Hints::from(err.cause.to_string()),
Self::Lowering(err) => err.hints(),
Self::RequirementsResolve(_, err) | Self::RequirementsInstall(_, err) => err.hints(),
_ => Hints::none(),
}
}
}

#[derive(Debug)]
enum MissingLibrary {
Header(String),
Expand Down Expand Up @@ -322,13 +337,6 @@ impl Display for BuildBackendError {
writeln!(f)?;
}

write!(
f,
"\n{}{} This usually indicates a problem with the package or the build environment.",
"hint".bold().cyan(),
":".bold()
)?;

Ok(())
}
}
Expand All @@ -354,14 +362,6 @@ impl Display for MissingHeaderError {
write!(f, "\n\n{}\n{}", "[stderr]".red(), self.stderr.join("\n"))?;
}

write!(
f,
"\n\n{}{} {}",
"hint".bold().cyan(),
":".bold(),
self.cause
)?;

Ok(())
}
}
Expand Down Expand Up @@ -467,9 +467,20 @@ mod test {
use std::process::ExitStatus;
use std::str::FromStr;
use uv_configuration::BuildOutput;
use uv_errors::{ErrorWithHints, Hint};
use uv_normalize::PackageName;
use uv_pep440::Version;

fn format_error_with_hints(err: &Error) -> String {
// Unix uses exit status, Windows uses exit code.
let formatted = std::error::Error::source(err)
.unwrap()
.to_string()
.replace("exit status: ", "exit code: ");
let formatted = ErrorWithHints::new(formatted, err.hints()).to_string();
anstream::adapter::strip_str(&formatted).to_string()
}

#[test]
fn missing_header() {
let output = PythonRunnerOutput {
Expand Down Expand Up @@ -506,12 +517,7 @@ mod test {
);

assert!(matches!(err, Error::MissingHeader { .. }));
// Unix uses exit status, Windows uses exit code.
let formatted = std::error::Error::source(&err)
.unwrap()
.to_string()
.replace("exit status: ", "exit code: ");
let formatted = anstream::adapter::strip_str(&formatted);
let formatted = format_error_with_hints(&err);
insta::assert_snapshot!(formatted, @r#"
Failed building wheel through setup.py (exit code: 0)

Expand Down Expand Up @@ -564,12 +570,7 @@ mod test {
Some("pygraphviz-1.11"),
);
assert!(matches!(err, Error::MissingHeader { .. }));
// Unix uses exit status, Windows uses exit code.
let formatted = std::error::Error::source(&err)
.unwrap()
.to_string()
.replace("exit status: ", "exit code: ");
let formatted = anstream::adapter::strip_str(&formatted);
let formatted = format_error_with_hints(&err);
insta::assert_snapshot!(formatted, @"
Failed building wheel through setup.py (exit code: 0)

Expand Down Expand Up @@ -612,12 +613,7 @@ mod test {
Some("pygraphviz-1.11"),
);
assert!(matches!(err, Error::MissingHeader { .. }));
// Unix uses exit status, Windows uses exit code.
let formatted = std::error::Error::source(&err)
.unwrap()
.to_string()
.replace("exit status: ", "exit code: ");
let formatted = anstream::adapter::strip_str(&formatted);
let formatted = format_error_with_hints(&err);
insta::assert_snapshot!(formatted, @r#"
Failed building wheel through setup.py (exit code: 0)

Expand Down Expand Up @@ -663,12 +659,7 @@ mod test {
Some("pygraphviz-1.11"),
);
assert!(matches!(err, Error::MissingHeader { .. }));
// Unix uses exit status, Windows uses exit code.
let formatted = std::error::Error::source(&err)
.unwrap()
.to_string()
.replace("exit status: ", "exit code: ");
let formatted = anstream::adapter::strip_str(&formatted);
let formatted = format_error_with_hints(&err);
insta::assert_snapshot!(formatted, @"
Failed building wheel through setup.py (exit code: 0)

Expand Down
1 change: 1 addition & 0 deletions crates/uv-dispatch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ uv-configuration = { workspace = true }
uv-distribution = { workspace = true }
uv-distribution-filename = { workspace = true }
uv-distribution-types = { workspace = true }
uv-errors = { workspace = true }
uv-git = { workspace = true }
uv-install-wheel = { workspace = true }
uv-installer = { workspace = true }
Expand Down
23 changes: 23 additions & 0 deletions crates/uv-dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,29 @@ pub enum BuildDispatchError {
Lookahead(#[from] uv_requirements::Error),
}

impl uv_errors::Hint for BuildDispatchError {
fn hints(&self) -> uv_errors::Hints<'_> {
match self {
Self::BuildFrontend(err) => err.hints(),
Self::Resolve(err) => err.hints(),
Self::Anyhow(err) => {
// Walk the anyhow error chain to find hint-bearing errors
// (e.g., ResolveError wrapped via `with_context`).
for cause in err.chain() {
if let Some(resolve_err) = cause.downcast_ref::<uv_resolver::ResolveError>() {
let hints = resolve_err.hints();
if !hints.is_empty() {
return hints;
}
}
}
uv_errors::Hints::none()
}
_ => uv_errors::Hints::none(),
}
}
}

impl IsBuildBackendError for BuildDispatchError {
fn is_build_backend_error(&self) -> bool {
match self {
Expand Down
Loading
Loading