diff --git a/Cargo.lock b/Cargo.lock index 5422a804b..4048247b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4804,6 +4804,7 @@ dependencies = [ "md-5", "pypi-types", "rayon", + "reqwest", "rustc-hash 2.0.0", "sha2", "thiserror", diff --git a/crates/uv-distribution/src/distribution_database.rs b/crates/uv-distribution/src/distribution_database.rs index 0ba87e723..ac8a81ebb 100644 --- a/crates/uv-distribution/src/distribution_database.rs +++ b/crates/uv-distribution/src/distribution_database.rs @@ -208,10 +208,16 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> { hashes: archive.hashes, filename: wheel.filename.clone(), }), - Err(Error::Extract(err)) if err.is_http_streaming_unsupported() => { - warn!( - "Streaming unsupported for {dist}; downloading wheel to disk ({err})" - ); + Err(Error::Extract(err)) => { + if err.is_http_streaming_unsupported() { + warn!( + "Streaming unsupported for {dist}; downloading wheel to disk ({err})" + ); + } else if err.is_http_streaming_failed() { + warn!("Streaming failed for {dist}; downloading wheel to disk ({err})"); + } else { + return Err(Error::Extract(err)); + } // If the request failed because streaming is unsupported, download the // wheel directly. diff --git a/crates/uv-extract/Cargo.toml b/crates/uv-extract/Cargo.toml index f5c3c5eb4..234eee8f6 100644 --- a/crates/uv-extract/Cargo.toml +++ b/crates/uv-extract/Cargo.toml @@ -21,6 +21,7 @@ fs-err = { workspace = true, features = ["tokio"] } futures = { workspace = true } md-5.workspace = true rayon = { workspace = true } +reqwest = { workspace = true } rustc-hash = { workspace = true } sha2 = { workspace = true } thiserror = { workspace = true } diff --git a/crates/uv-extract/src/error.rs b/crates/uv-extract/src/error.rs index 275caed53..3cfaeb35a 100644 --- a/crates/uv-extract/src/error.rs +++ b/crates/uv-extract/src/error.rs @@ -28,4 +28,19 @@ impl Error { Self::AsyncZip(async_zip::error::ZipError::FeatureNotSupported(_)) ) } + + /// Returns `true` if the error is due to HTTP streaming request failed. + pub fn is_http_streaming_failed(&self) -> bool { + match self { + Self::AsyncZip(async_zip::error::ZipError::UpstreamReadError(_)) => true, + Self::Io(err) => { + if let Some(inner) = err.get_ref() { + inner.downcast_ref::().is_some() + } else { + false + } + } + _ => false, + } + } }