Skip to content

Commit

Permalink
Show interpreter source during Python discovery query errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Oct 4, 2024
1 parent ff1a896 commit b745cd7
Showing 1 changed file with 22 additions and 7 deletions.
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

0 comments on commit b745cd7

Please sign in to comment.