From 41f11d030d55d625f364868e2869f555bae9c716 Mon Sep 17 00:00:00 2001 From: overtrue Date: Mon, 23 Nov 2026 15:00:00 +0800 Subject: [PATCH] refactor(gateway): use native errors for table listings and multipart headers --- rustfs/src/app/dto_values.rs | 7 ++++--- rustfs/src/app/table_list_isolation.rs | 6 +++--- rustfs/src/protocols/client/multipart.rs | 8 ++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/rustfs/src/app/dto_values.rs b/rustfs/src/app/dto_values.rs index 7f1e5496c0..5295efa6c5 100644 --- a/rustfs/src/app/dto_values.rs +++ b/rustfs/src/app/dto_values.rs @@ -16,14 +16,14 @@ //! //! Responsible for: the bucket name, object key, timestamp, owner and stored-configuration //! conversions a use case needs to build a gateway output from what the store returned, under the -//! rule in [`crate::app`]; and [`seam_error`], the one answer for a value the s3s compatibility -//! seam refused. +//! rule in [`crate::app`]. //! NOT responsible for: validating names a client sends (the edge that accepted the request did), //! or deciding what a use case lists. //! Upstream: the use cases in `crate::app`. Downstream: `rustfs_gateway_types`. use super::storage_api::bucket_usecase::bucket::utils::{BucketConfigXml, serialize}; use super::storage_api::bucket_usecase::s3_api::bucket::{RUSTFS_OWNER_DISPLAY_NAME, RUSTFS_OWNER_ID}; +#[cfg(test)] use rustfs_gateway_types::compat::{ConversionError, NameRefusal}; use rustfs_gateway_types::dto::Owner; use rustfs_gateway_types::{BucketName, ETag, NamePolicy, NameValidator, ObjectKey, Stricter, Timestamp}; @@ -63,7 +63,7 @@ pub(crate) fn stored_bucket_name(name: &str) -> S3Result { }) } -/// What a legacy edge answers when the s3s compatibility seam refuses a value of an admitted request. +/// The legacy error expected by compatibility tests when the s3s seam refuses an admitted value. /// /// - An object key below the gateway's key floor (empty, over 1024 bytes, a NUL) is refused as /// `validate_object_key` refuses one: `400 InvalidArgument`, with a fixed message. An edge whose @@ -71,6 +71,7 @@ pub(crate) fn stored_bucket_name(name: &str) -> S3Result { /// - A bucket name below the bucket floor is a server fault: s3s admits only `[a-z0-9.-]{3,63}`, /// which the floor always accepts, so no bucket a request names reaches it. /// - Any other refusal is a value the gateway shape cannot hold: a server fault. +#[cfg(test)] pub(crate) fn seam_error(error: ConversionError) -> S3Error { match error.name_kind() { Some(NameRefusal::ObjectKey) => S3Error::with_message(S3ErrorCode::InvalidArgument, "Invalid object key"), diff --git a/rustfs/src/app/table_list_isolation.rs b/rustfs/src/app/table_list_isolation.rs index beeb258a6b..dbf3632fe7 100644 --- a/rustfs/src/app/table_list_isolation.rs +++ b/rustfs/src/app/table_list_isolation.rs @@ -18,8 +18,8 @@ use crate::app::storage_api::bucket_usecase::access::{ use crate::app::storage_api::bucket_usecase::contract::list::{ListObjectVersionsInfo, ListObjectsV2Info, ListOperations as _}; use crate::app::storage_api::bucket_usecase::{ECStore, StorageObjectInfo as ObjectInfo}; use crate::app::storage_api::multipart_usecase::contract::multipart::{ListMultipartsInfo, MultipartInfo}; -use crate::app::storage_api::s3::{S3Error, S3ErrorCode, S3Result}; use crate::error::ApiError; +use rustfs_s3_types::{S3Error, S3ErrorCode, S3Result}; use std::collections::HashSet; use std::sync::Arc; use uuid::Uuid; @@ -70,12 +70,12 @@ pub(crate) struct ListMultipartUploadsRequest<'a> { fn table_list_scan_limit_error() -> S3Error { S3Error::with_message( S3ErrorCode::SlowDown, - "Table listing exceeded the protected scan limit; retry with a narrower prefix".to_string(), + "Table listing exceeded the protected scan limit; retry with a narrower prefix", ) } fn invalid_table_list_cursor() -> S3Error { - S3Error::with_message(S3ErrorCode::InvalidArgument, "Invalid table listing continuation token".to_string()) + S3Error::with_message(S3ErrorCode::InvalidArgument, "Invalid table listing continuation token") } fn list_objects_v2_operation(incl_deleted: bool) -> &'static str { diff --git a/rustfs/src/protocols/client/multipart.rs b/rustfs/src/protocols/client/multipart.rs index f7a18b6fe2..1cbf5e5ba1 100644 --- a/rustfs/src/protocols/client/multipart.rs +++ b/rustfs/src/protocols/client/multipart.rs @@ -156,10 +156,10 @@ pub(super) fn complete_multipart_output( ] { if let Some(value) = value { http::HeaderValue::from_str(&value).map_err(|_| { - crate::app::dto_values::seam_error(rustfs_gateway_types::compat::ConversionError { - field, - reason: "not a header value", - }) + S3Error::with_message( + S3ErrorCode::InternalError, + format!("failed to convert through the gateway compatibility seam: {field}: not a header value"), + ) })?; } }