Skip to content

Commit

Permalink
Ignore query errors during uv toolchain list
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Jun 18, 2024
1 parent b8c0391 commit fb3dbda
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/uv-toolchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub use crate::discovery::{
};
pub use crate::environment::PythonEnvironment;
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::prefix::Prefix;
pub use crate::python_version::PythonVersion;
Expand Down
31 changes: 27 additions & 4 deletions crates/uv/src/commands/toolchain/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ use std::fmt::Write;

use anyhow::Result;

use tracing::debug;
use uv_cache::Cache;
use uv_configuration::PreviewMode;
use uv_fs::Simplified;
use uv_toolchain::downloads::PythonDownloadRequest;
use uv_toolchain::{
find_toolchains, DiscoveryError, SystemPython, Toolchain, ToolchainNotFound, ToolchainRequest,
ToolchainSource, ToolchainSources,
find_toolchains, DiscoveryError, InterpreterError, SystemPython, Toolchain, ToolchainNotFound,
ToolchainRequest, ToolchainSource, ToolchainSources,
};
use uv_warnings::warn_user;

Expand Down Expand Up @@ -59,10 +60,32 @@ pub(crate) async fn list(
&ToolchainSources::All(PreviewMode::Enabled),
cache,
)
// Raise any errors encountered during discovery
// Raise discovery errors if relevant
.filter(|result| {
result.as_ref().err().map_or(true, |err| match err {
// 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
DiscoveryError::Query(err) => 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());
false
}
InterpreterError::NotFound(path) => {
debug!("Skipping missing interpreter at {}", path.display());
false
}
},
_ => true,
})
})
.collect::<Result<Vec<Result<Toolchain, ToolchainNotFound>>, DiscoveryError>>()?
.into_iter()
// Then drop any "missing" toolchains
// Drop any "missing" toolchains
.filter_map(std::result::Result::ok);

let mut output = BTreeSet::new();
Expand Down

0 comments on commit fb3dbda

Please sign in to comment.