From 2dd963b30f0648cd52756a2644f9efaaad6e9e0e Mon Sep 17 00:00:00 2001 From: kamille Date: Wed, 1 Nov 2023 13:12:38 +0800 Subject: [PATCH] optimize error msg for better debugging. --- object_store/src/client/retry.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/object_store/src/client/retry.rs b/object_store/src/client/retry.rs index 39a913142e09..8bf46b1ba74b 100644 --- a/object_store/src/client/retry.rs +++ b/object_store/src/client/retry.rs @@ -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, status: Option, @@ -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}")?; @@ -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, }) @@ -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() { @@ -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), }) @@ -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), })