Repository: astral-sh/uv
File: crates/uv-python/src/discovery.rs (Rust)

Code before:
    debug!("Looking for exact match for request {request}");
    let result = find_python_installation(request, environments, preference, cache, preview);
    match result {
        Ok(Ok(installation)) => {
            warn_on_unsupported_python(installation.interpreter());
            return Ok(Ok(installation));
        }
        // Continue if we can't find a matching Python and ignore non-critical discovery errors
        Ok(Err(_)) => {}
        Err(ref err) if !err.is_critical() => {}
        _ => return Ok(result?),
    }

    // Attempt to download the version if downloads are enabled
    if downloads_enabled
        && let Some(download_request) = PythonDownloadRequest::from_request(request)
    {
        let download = download_request
            .clone()
            .fill()
            .map(|request| download_list.find(&request));
        if let Some(download) = match download {
            Ok(Ok(download)) => Some(download),
            Ok(Err(crate::downloads::Error::NoDownloadFound(_))) => None,
            Ok(Err(error)) => return Err(error.into()),
            Err(error) => return Err(error.into()),
        } {
            let installation = PythonInstallation::fetch(
                download,
                client,
                retry_policy,
                cache,
                reporter,
                python_install_mirror,
                pypy_install_mirror,
                preview,
            )
            .await?;

            return Ok(Ok(installation));
        }
    }

    // If both approaches fail, and a specific patch version was requested try
    // again allowing a different patch version
    if let Some(request) = match request {
        PythonRequest::Version(version) => {
            if version.has_patch() {
                Some(PythonRequest::Version(version.clone().without_patch()))
            } else {
                None

Review comment (suggestion):
There's a question here regarding if we should instead just report these errors and continue instead of propagating them upstream, as this is kind of a breaking change.

Code after:
    preview: Preview,
) -> Result<PythonInstallation, crate::Error> {
    debug!("Starting Python discovery for {request}");
    let original_request = request;

    let mut previous_fetch_failed = false;

    let request_without_patch = match request {
        PythonRequest::Version(version) => {
            if version.has_patch() {
                Some(PythonRequest::Version(version.clone().without_patch()))
            } else {
                None
            }
        }
        PythonRequest::ImplementationVersion(implementation, version) => Some(
            PythonRequest::ImplementationVersion(*implementation, version.clone().without_patch()),
        ),
        _ => None,
    };

    for (attempt, request) in iter::once(original_request)
        .chain(request_without_patch.iter())
        .chain(iter::once(&PythonRequest::Default))
        .enumerate()
    {
        debug!(
            "Looking for {request}{}",
            if request != original_request {
                format!(" attempt {attempt} (fallback after failing to find: {original_request})")
            } else {
                String::new()
            }
        );
        let result = find_python_installation(request, environments, preference, cache, preview);
        let error = match result {
            Ok(Ok(installation)) => {
                warn_on_unsupported_python(installation.interpreter());
                return Ok(installation);
            }
            // Continue if we can't find a matching Python and ignore non-critical discovery errors
            Ok(Err(error)) => error.into(),
            Err(error) if !error.is_critical() => error.into(),
            Err(error) => return Err(error.into()),
        };

        // Attempt to download the version if downloads are enabled
        if downloads_enabled
            && !previous_fetch_failed
            && let Some(download_request) = PythonDownloadRequest::from_request(request)
        {