From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 560F61FF17C for ; Wed, 23 Jul 2025 12:25:02 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C221BDC31; Wed, 23 Jul 2025 12:26:18 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Wed, 23 Jul 2025 12:26:00 +0200 Message-ID: <20250723102601.495806-3-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250723102601.495806-1-c.ebner@proxmox.com> References: <20250723102601.495806-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1753266364878 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.045 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox 2/3] s3 client: refactor error response body into dedicated helper X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Places body utf8 encoding and logging into a common place instead of having it scattered over various places in the response status checks. No functional changes intended. Signed-off-by: Christian Ebner --- proxmox-s3-client/src/response_reader.rs | 46 ++++++++---------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/proxmox-s3-client/src/response_reader.rs b/proxmox-s3-client/src/response_reader.rs index 41e8c6d8..7aed4201 100644 --- a/proxmox-s3-client/src/response_reader.rs +++ b/proxmox-s3-client/src/response_reader.rs @@ -2,7 +2,7 @@ use std::str::FromStr; use anyhow::{anyhow, bail, Context, Error}; use http_body_util::BodyExt; -use hyper::body::Incoming; +use hyper::body::{Bytes, Incoming}; use hyper::header::HeaderName; use hyper::http::header; use hyper::http::StatusCode; @@ -166,11 +166,7 @@ impl ResponseReader { StatusCode::OK => (), StatusCode::NOT_FOUND => bail!("bucket does not exist"), status_code => { - if let Ok(body) = String::from_utf8(body.to_vec()) { - if !body.is_empty() { - tracing::error!("{body}"); - } - } + Self::log_error_response_utf8(body); bail!("unexpected status code {status_code}") } } @@ -193,11 +189,7 @@ impl ResponseReader { StatusCode::OK => (), StatusCode::NOT_FOUND => return Ok(None), status_code => { - if let Ok(body) = String::from_utf8(body.to_vec()) { - if !body.is_empty() { - tracing::error!("{body}"); - } - } + Self::log_error_response_utf8(body); bail!("unexpected status code {status_code}") } } @@ -229,11 +221,7 @@ impl ResponseReader { StatusCode::FORBIDDEN => bail!("object is archived and inaccessible until restored"), status_code => { let body = content.collect().await?.to_bytes(); - if let Ok(body) = String::from_utf8(body.to_vec()) { - if !body.is_empty() { - tracing::error!("{body}"); - } - } + Self::log_error_response_utf8(body); bail!("unexpected status code {status_code}") } } @@ -264,11 +252,7 @@ impl ResponseReader { StatusCode::CONFLICT => return Ok(PutObjectResponse::NeedsRetry), StatusCode::BAD_REQUEST => bail!("invalid request"), status_code => { - if let Ok(body) = String::from_utf8(body.to_vec()) { - if !body.is_empty() { - tracing::error!("{body}"); - } - } + Self::log_error_response_utf8(body); bail!("unexpected status code {status_code}") } }; @@ -301,11 +285,7 @@ impl ResponseReader { StatusCode::OK => (), StatusCode::BAD_REQUEST => bail!("invalid request"), status_code => { - if let Ok(body) = String::from_utf8(body.to_vec()) { - if !body.is_empty() { - tracing::error!("{body}"); - } - } + Self::log_error_response_utf8(body); bail!("unexpected status code {status_code}") } }; @@ -327,11 +307,7 @@ impl ResponseReader { StatusCode::NOT_FOUND => bail!("object not found"), StatusCode::FORBIDDEN => bail!("the source object is not in the active tier"), status_code => { - if let Ok(body) = String::from_utf8(body.to_vec()) { - if !body.is_empty() { - tracing::error!("{body}"); - } - } + Self::log_error_response_utf8(body); bail!("unexpected status code {status_code}") } } @@ -357,6 +333,14 @@ impl ResponseReader { }) } + fn log_error_response_utf8(body: Bytes) { + if let Ok(body) = String::from_utf8(body.to_vec()) { + if !body.is_empty() { + tracing::error!("{body}"); + } + } + } + fn parse_header(name: HeaderName, headers: &HeaderMap) -> Result where ::Err: Send + Sync + 'static, -- 2.47.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel