Ignore query errors during uv toolchain list (#4382)

Closes #4380 

This is the same logic as `should_stop_discovery` but I changed the log
level and duplicated it because I don't really want that method to be
public. Maybe it should be though?
This commit is contained in:
Zanie Blue 2024-06-18 10:52:59 -04:00 committed by GitHub
parent 1ce21475a5
commit 58f53f01bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 33 additions and 25 deletions

View file

@ -454,11 +454,12 @@ fn result_satisfies_system_python(
}) })
} }
/// Check if an encountered error should stop discovery. /// Check if an encountered error is critical and should stop discovery.
/// ///
/// Returns false when an error could be due to a faulty toolchain and we should continue searching for a working one. /// Returns false when an error could be due to a faulty toolchain and we should continue searching for a working one.
fn should_stop_discovery(err: &Error) -> bool { impl Error {
match err { pub fn is_critical(&self) -> bool {
match self {
// When querying the toolchain interpreter fails, we will only raise errors that demonstrate that something is broken // When querying the toolchain interpreter fails, we will only raise errors that demonstrate that something is broken
// If the toolchain interpreter returned a bad response, we'll continue searching for one that works // If the toolchain interpreter returned a bad response, we'll continue searching for one that works
Error::Query(err) => match err { Error::Query(err) => match err {
@ -468,7 +469,7 @@ fn should_stop_discovery(err: &Error) -> bool {
InterpreterError::QueryScript { path, .. } InterpreterError::QueryScript { path, .. }
| InterpreterError::UnexpectedResponse { path, .. } | InterpreterError::UnexpectedResponse { path, .. }
| InterpreterError::StatusCode { path, .. } => { | InterpreterError::StatusCode { path, .. } => {
trace!("Skipping bad interpreter at {}", path.display()); debug!("Skipping bad interpreter at {}: {err}", path.display());
false false
} }
InterpreterError::NotFound(path) => { InterpreterError::NotFound(path) => {
@ -478,6 +479,7 @@ fn should_stop_discovery(err: &Error) -> bool {
}, },
_ => true, _ => true,
} }
}
} }
fn find_toolchain_at_file(path: &PathBuf, cache: &Cache) -> Result<ToolchainResult, Error> { fn find_toolchain_at_file(path: &PathBuf, cache: &Cache) -> Result<ToolchainResult, Error> {
@ -641,7 +643,7 @@ pub(crate) fn find_toolchain(
let mut toolchains = find_toolchains(request, system, sources, cache); let mut toolchains = find_toolchains(request, system, sources, cache);
if let Some(result) = toolchains.find(|result| { if let Some(result) = toolchains.find(|result| {
// Return the first critical discovery error or toolchain result // Return the first critical discovery error or toolchain result
result.as_ref().err().map_or(true, should_stop_discovery) result.as_ref().err().map_or(true, Error::is_critical)
}) { }) {
result result
} else { } else {

View file

@ -7,7 +7,7 @@ pub use crate::discovery::{
}; };
pub use crate::environment::PythonEnvironment; pub use crate::environment::PythonEnvironment;
pub use crate::implementation::ImplementationName; pub use crate::implementation::ImplementationName;
pub use crate::interpreter::Interpreter; pub use crate::interpreter::{Error as InterpreterError, Interpreter};
pub use crate::pointer_size::PointerSize; pub use crate::pointer_size::PointerSize;
pub use crate::prefix::Prefix; pub use crate::prefix::Prefix;
pub use crate::python_version::PythonVersion; pub use crate::python_version::PythonVersion;

View file

@ -59,10 +59,16 @@ pub(crate) async fn list(
&ToolchainSources::All(PreviewMode::Enabled), &ToolchainSources::All(PreviewMode::Enabled),
cache, cache,
) )
// Raise any errors encountered during discovery // Raise discovery errors if critical
.filter(|result| {
result
.as_ref()
.err()
.map_or(true, DiscoveryError::is_critical)
})
.collect::<Result<Vec<Result<Toolchain, ToolchainNotFound>>, DiscoveryError>>()? .collect::<Result<Vec<Result<Toolchain, ToolchainNotFound>>, DiscoveryError>>()?
.into_iter() .into_iter()
// Then drop any "missing" toolchains // Drop any "missing" toolchains
.filter_map(std::result::Result::ok); .filter_map(std::result::Result::ok);
let mut output = BTreeSet::new(); let mut output = BTreeSet::new();