Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show interpreter source during Python discovery query errors #7928

Merged
merged 1 commit into from
Oct 7, 2024
Merged
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
29 changes: 22 additions & 7 deletions crates/uv-python/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,12 @@ pub enum Error {
Io(#[from] io::Error),

/// An error was encountering when retrieving interpreter information.
#[error(transparent)]
Query(#[from] crate::interpreter::Error),
#[error("Failed to inspect Python interpreter from {2} at `{}` ", .1.user_display())]
Query(
#[source] Box<crate::interpreter::Error>,
PathBuf,
PythonSource,
),

/// An error was encountered when interacting with a managed Python installation.
#[error(transparent)]
Expand Down Expand Up @@ -600,7 +604,7 @@ fn python_interpreters_from_executables<'a>(
path.display()
);
})
.map_err(Error::from)
.map_err(|err| Error::Query(Box::new(err), path, source))
.inspect_err(|err| debug!("{err}")),
Err(err) => Err(err),
})
Expand Down Expand Up @@ -674,14 +678,17 @@ impl Error {
match self {
// When querying the Python interpreter fails, we will only raise errors that demonstrate that something is broken
// If the Python interpreter returned a bad response, we'll continue searching for one that works
Error::Query(err) => match err {
Error::Query(err, _, source) => match &**err {
InterpreterError::Encode(_)
| InterpreterError::Io(_)
| InterpreterError::SpawnFailed { .. } => true,
InterpreterError::QueryScript { path, .. }
| InterpreterError::UnexpectedResponse { path, .. }
| InterpreterError::StatusCode { path, .. } => {
debug!("Skipping bad interpreter at {}: {err}", path.display());
debug!(
"Skipping bad interpreter at {} from {source}: {err}",
path.display()
);
false
}
InterpreterError::NotFound(path) => {
Expand Down Expand Up @@ -747,7 +754,11 @@ pub fn find_python_installations<'a>(
environment_preference: environments,
}))
}
Err(err) => Err(err.into()),
Err(err) => Err(Error::Query(
Box::new(err),
path.clone(),
PythonSource::ProvidedPath,
)),
}
} else {
Err(Error::SourceNotAllowed(
Expand All @@ -770,7 +781,11 @@ pub fn find_python_installations<'a>(
environment_preference: environments,
}))
}
Err(err) => Err(err.into()),
Err(err) => Err(Error::Query(
Box::new(err),
path.clone(),
PythonSource::ProvidedPath,
)),
}
} else {
Err(Error::SourceNotAllowed(
Expand Down
Loading