Show when we retried requests (#4725)

In #3514 and #2755, users had intermittent network errors, but it was
not always clear whether we had already retried these requests or not.
Building upon https://github.com/TrueLayer/reqwest-middleware/pull/159,
this PR adds the number of retries to the error message, so we can see
at first glance where we're missing retries and where we might need to
change retry settings.

Example error trace:

```
Could not connect, are you offline?
  Caused by: Request failed after 3 retries
  Caused by: error sending request for url (https://pypi.org/simple/uv/)
  Caused by: client error (Connect)
  Caused by: dns error: failed to lookup address information: Name or service not known
  Caused by: failed to lookup address information: Name or service not known
```

This code is ugly since i'm missing a better pattern for attaching
context to reqwest middleware errors in
https://github.com/TrueLayer/reqwest-middleware/pull/159.
This commit is contained in:
konsti 2024-07-02 19:04:11 +02:00 committed by GitHub
parent 12e12d066d
commit 4b19319485
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 80 additions and 51 deletions

View file

@ -10,7 +10,7 @@ use crate::platform::{self, Arch, Libc, Os};
use crate::toolchain::ToolchainKey;
use crate::{Interpreter, PythonVersion, ToolchainRequest, VersionRequest};
use thiserror::Error;
use uv_client::BetterReqwestError;
use uv_client::WrappedReqwestError;
use futures::TryStreamExt;
@ -30,7 +30,7 @@ pub enum Error {
#[error("Invalid request key, too many parts: {0}")]
TooManyParts(String),
#[error("Download failed")]
NetworkError(#[from] BetterReqwestError),
NetworkError(#[from] WrappedReqwestError),
#[error("Download failed")]
NetworkMiddlewareError(#[source] anyhow::Error),
#[error("Failed to extract archive: {0}")]
@ -450,7 +450,7 @@ impl PythonDownload {
impl From<reqwest::Error> for Error {
fn from(error: reqwest::Error) -> Self {
Self::NetworkError(BetterReqwestError::from(error))
Self::NetworkError(WrappedReqwestError::from(error))
}
}
@ -459,7 +459,7 @@ impl From<reqwest_middleware::Error> for Error {
match error {
reqwest_middleware::Error::Middleware(error) => Self::NetworkMiddlewareError(error),
reqwest_middleware::Error::Reqwest(error) => {
Self::NetworkError(BetterReqwestError::from(error))
Self::NetworkError(WrappedReqwestError::from(error))
}
}
}