diff --git a/crates/puffin-client/src/client.rs b/crates/puffin-client/src/client.rs index 9c220dd5d..0be0b6b3a 100644 --- a/crates/puffin-client/src/client.rs +++ b/crates/puffin-client/src/client.rs @@ -126,6 +126,7 @@ impl RegistryClientBuilder { pub struct RegistryClient { pub(crate) index: Url, pub(crate) extra_index: Vec, + /// Ignore the package index, instead relying on local archives and caches. pub(crate) no_index: bool, pub(crate) proxy: Url, pub(crate) client: ClientWithMiddleware, @@ -136,7 +137,7 @@ impl RegistryClient { /// Fetch a package from the `PyPI` simple API. pub async fn simple(&self, package_name: impl AsRef) -> Result { if self.no_index { - return Err(Error::PackageNotFound(package_name.as_ref().to_string())); + return Err(Error::NoIndex(package_name.as_ref().to_string())); } for index in std::iter::once(&self.index).chain(self.extra_index.iter()) { @@ -187,7 +188,7 @@ impl RegistryClient { /// Fetch the metadata from a wheel file. pub async fn file(&self, file: File) -> Result { if self.no_index { - return Err(Error::FileNotFound(file.filename)); + return Err(Error::NoIndex(file.filename)); } // Per PEP 658, if `data-dist-info-metadata` is available, we can request it directly; @@ -203,7 +204,7 @@ impl RegistryClient { // Fetch from the index. let text = self.file_impl(&url).await.map_err(|err| { if err.status() == Some(StatusCode::NOT_FOUND) { - Error::FileNotFound(file.filename.to_string()) + Error::FileNotFound(file.filename, err) } else { err.into() } @@ -228,7 +229,7 @@ impl RegistryClient { url: &Url, ) -> Result, Error> { if self.no_index { - return Err(Error::ResourceNotFound(url.clone())); + return Err(Error::NoIndex(url.to_string())); } Ok(Box::new( diff --git a/crates/puffin-client/src/error.rs b/crates/puffin-client/src/error.rs index 84e438c15..a4bf42303 100644 --- a/crates/puffin-client/src/error.rs +++ b/crates/puffin-client/src/error.rs @@ -1,5 +1,4 @@ use thiserror::Error; -use url::Url; use puffin_package::pypi_types; @@ -9,6 +8,9 @@ pub enum Error { #[error(transparent)] UrlParseError(#[from] url::ParseError), + #[error("{0} isn't available locally, but making network requests to registries was banned.")] + NoIndex(String), + /// The package was not found in the registry. /// /// Make sure the package name is spelled correctly and that you've @@ -21,12 +23,8 @@ pub enum Error { MetadataParseError(#[from] pypi_types::Error), /// The metadata file was not found in the registry. - #[error("File `{0}` was not found in the registry.")] - FileNotFound(String), - - /// The resource was not found in the registry. - #[error("Resource `{0}` was not found in the registry.")] - ResourceNotFound(Url), + #[error("File `{0}` was not found in the registry at {1}.")] + FileNotFound(String, #[source] reqwest_middleware::Error), /// A generic request error happened while making a request. Refer to the /// error message for more details.