Skip to content

Commit

Permalink
optimize error msg for better debugging.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachelint committed Nov 1, 2023
1 parent b163b19 commit 2dd963b
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions object_store/src/client/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ use tracing::info;
#[derive(Debug)]
pub struct Error {
retries: usize,
max_retries: usize,
elapsed: Duration,
retry_timeout: Duration,
message: String,
source: Option<reqwest::Error>,
status: Option<StatusCode>,
Expand All @@ -39,8 +42,8 @@ impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"response error \"{}\", after {} retries",
self.message, self.retries
"response error \"{}\", after {} retries in {:?}, max_retries:{}, retry_timeout:{:?}",
self.message, self.retries, self.elapsed, self.max_retries, self.retry_timeout
)?;
if let Some(source) = &self.source {
write!(f, ": {source}")?;
Expand Down Expand Up @@ -172,6 +175,9 @@ impl RetryExt for reqwest::RequestBuilder {
return Err(Error{
message: "not modified".to_string(),
retries,
max_retries,
elapsed: now.elapsed(),
retry_timeout,
status: Some(r.status()),
source: None,
})
Expand All @@ -187,13 +193,15 @@ impl RetryExt for reqwest::RequestBuilder {
return Err(Error{
message,
retries,
max_retries,
elapsed: now.elapsed(),
retry_timeout,
status: Some(r.status()),
source: None,
})
}
Err(e) => {
let status = r.status();

if retries == max_retries
|| now.elapsed() > retry_timeout
|| !status.is_server_error() {
Expand All @@ -211,6 +219,9 @@ impl RetryExt for reqwest::RequestBuilder {
return Err(Error{
message,
retries,
max_retries,
elapsed: now.elapsed(),
retry_timeout,
status: Some(status),
source: Some(e),
})
Expand Down Expand Up @@ -240,7 +251,10 @@ impl RetryExt for reqwest::RequestBuilder {

return Err(Error{
retries,
message: "request error".to_string(),
max_retries,
elapsed: now.elapsed(),
retry_timeout,
message: format!("request error, do_retry:{do_retry}"),
status: e.status(),
source: Some(e),
})
Expand Down

0 comments on commit 2dd963b

Please sign in to comment.