refactor(gateway): use native errors for table listings and multipart headers

This commit is contained in:
overtrue
2026-11-23 15:00:00 +08:00
parent 69514b18de
commit 41f11d030d
3 changed files with 11 additions and 10 deletions
+4 -3
View File
@@ -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<BucketName> {
})
}
/// 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<BucketName> {
/// - 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"),
+3 -3
View File
@@ -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 {
+4 -4
View File
@@ -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"),
)
})?;
}
}