This is an automated email from the ASF dual-hosted git repository.

Xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 4958749126 fix(services/s3): map CompleteMultipartUpload NoSuchUpload 
to Unexpected (#8585)
4958749126 is described below

commit 495874912637d99b8a8e0934c295e1a83110ca50
Author: Harrison Crosse <[email protected]>
AuthorDate: Mon Nov 23 16:54:42 2026 -0500

    fix(services/s3): map CompleteMultipartUpload NoSuchUpload to Unexpected 
(#8585)
    
    * fix(services/s3): preserve CompleteMultipartUpload error semantics
    
    * fix(services/s3): scope NoSuchUpload mapping to CompleteMultipartUpload
---
 core/services/s3/src/backend.rs | 119 ++++++++++++++++++++++++++++++++++++++++
 core/services/s3/src/core.rs    |  77 ++++++++++++++++++++++++++
 2 files changed, 196 insertions(+)

diff --git a/core/services/s3/src/backend.rs b/core/services/s3/src/backend.rs
index b8702ddd69..04585e3de4 100644
--- a/core/services/s3/src/backend.rs
+++ b/core/services/s3/src/backend.rs
@@ -2850,6 +2850,125 @@ mod tests {
         assert!(transport.requests().is_empty());
     }
 
+    #[derive(Clone)]
+    struct CompleteMultipartErrorTransport {
+        complete_body: &'static str,
+    }
+
+    impl HttpTransport for CompleteMultipartErrorTransport {
+        async fn fetch(&self, req: Request<Buffer>) -> 
Result<Response<HttpBody>> {
+            let query = req.uri().query().unwrap_or_default();
+            if req.headers().contains_key(constants::X_AMZ_COPY_SOURCE) {
+                return Ok(S3ExpressMockTransport::response(
+                    StatusCode::OK,
+                    "<CopyPartResult><ETag>\"etag\"</ETag>\
+                     
<LastModified>2026-08-24T00:00:00Z</LastModified></CopyPartResult>",
+                ));
+            }
+            if query == "uploads" {
+                return Ok(S3ExpressMockTransport::response(
+                    StatusCode::OK,
+                    
"<InitiateMultipartUploadResult><UploadId>upload-id</UploadId>\
+                     </InitiateMultipartUploadResult>",
+                ));
+            }
+            // Abort cleanup must not fall through to the UploadPart 200 OK 
branch.
+            if req.method() == Method::DELETE {
+                return Ok(S3ExpressMockTransport::response(
+                    StatusCode::NO_CONTENT,
+                    Bytes::new(),
+                ));
+            }
+            if req.method() == Method::POST && query.contains("uploadId=") {
+                assert_eq!(
+                    req.headers()
+                        .get(http::header::IF_MATCH)
+                        .and_then(|v| v.to_str().ok()),
+                    Some("\"expected\""),
+                    "CompleteMultipartUpload must carry If-Match"
+                );
+                return Ok(S3ExpressMockTransport::response(
+                    StatusCode::NOT_FOUND,
+                    self.complete_body,
+                ));
+            }
+
+            let mut response = 
S3ExpressMockTransport::response(StatusCode::OK, Bytes::new());
+            response
+                .headers_mut()
+                .insert(http::header::ETAG, 
HeaderValue::from_static("\"etag\""));
+            Ok(response)
+        }
+    }
+
+    #[tokio::test]
+    async fn 
test_complete_multipart_upload_error_classification_with_if_match() {
+        const PART_SIZE: usize = 5 * 1024 * 1024;
+        let part_payload = Bytes::from(vec![0u8; PART_SIZE]);
+        let cases = [
+            (
+                "NoSuchUpload 404",
+                "<Error><Code>NoSuchUpload</Code><Message>The specified upload 
does not exist.</Message></Error>",
+                ErrorKind::Unexpected,
+                Some("NoSuchUpload"),
+            ),
+            (
+                "NoSuchKey 404",
+                "<Error><Code>NoSuchKey</Code><Message>The specified key does 
not exist.</Message></Error>",
+                ErrorKind::ConditionNotMatch,
+                None,
+            ),
+        ];
+
+        for (label, complete_body, expected_kind, expected_msg_substr) in 
cases {
+            let transport = CompleteMultipartErrorTransport { complete_body };
+            let op = Operator::new(
+                S3Builder::default()
+                    .bucket("example")
+                    .region("us-west-2")
+                    .skip_signature()
+                    .disable_config_load()
+                    .disable_ec2_metadata(),
+            )
+            .unwrap()
+            .with_context(
+                OperationContext::new()
+                    
.with_http_transport(HttpTransporter::new(transport.clone())),
+            );
+
+            let mut writer = op
+                .writer_with("target")
+                .if_match("\"expected\"")
+                .chunk(PART_SIZE)
+                .await
+                .unwrap();
+            writer.write(part_payload.clone()).await.unwrap();
+            writer.write("x").await.unwrap();
+            let err = writer
+                .close()
+                .await
+                .expect_err("multipart write close must fail");
+            assert_eq!(err.kind(), expected_kind, "write {label}");
+            assert!(!err.is_temporary(), "write {label}");
+            if let Some(msg) = expected_msg_substr {
+                assert!(err.to_string().contains(msg), "write {label}: {err}");
+            }
+
+            let err = op
+                .copy_with("source", "target")
+                .if_match("\"expected\"")
+                .source_content_length_hint(PART_SIZE as u64 + 1)
+                .chunk(PART_SIZE)
+                .await
+                .expect_err("multipart copy must fail");
+            assert_eq!(err.kind(), expected_kind, "copy {label}");
+            assert!(!err.is_temporary(), "copy {label}");
+            if let Some(msg) = expected_msg_substr {
+                assert!(err.to_string().contains(msg), "copy {label}: {err}");
+            }
+        }
+    }
+
     #[cfg(not(target_arch = "wasm32"))]
     #[derive(Debug)]
     struct ExpiredSsoSession;
diff --git a/core/services/s3/src/core.rs b/core/services/s3/src/core.rs
index 1bfeeba6ca..f6e974577c 100644
--- a/core/services/s3/src/core.rs
+++ b/core/services/s3/src/core.rs
@@ -2409,6 +2409,12 @@ pub fn parse_s3_error_code(ctx: ErrorContext, code: 
&str) -> Option<(ErrorKind,
         // CopyObject. Classify the error code explicitly because the HTTP
         // status alone cannot preserve the NotFound semantics in this case.
         "NoSuchKey" => Some((ErrorKind::NotFound, false)),
+        // On CompleteMultipartUpload, NoSuchUpload means the upload session no
+        // longer exists rather than a missing target key, so it must not map 
to
+        // NotFound or be rewritten to ConditionNotMatch under if_match.
+        "NoSuchUpload" if ctx.service_operation == 
ServiceOperation("CompleteMultipartUpload") => {
+            Some((ErrorKind::Unexpected, false))
+        }
         // > Your socket connection to the server was not read from
         // > or written to within the timeout period."
         //
@@ -2497,4 +2503,75 @@ mod error_tests {
             assert!(!err.is_temporary(), "status {status}");
         }
     }
+
+    #[test]
+    fn complete_multipart_upload_no_such_upload_and_no_such_key() {
+        let no_such_upload_xml = "<Error><Code>NoSuchUpload</Code><Message>The 
specified upload does not exist.</Message></Error>";
+        let no_such_key_xml = "<Error><Code>NoSuchKey</Code><Message>The 
specified key does not exist.</Message></Error>";
+
+        for caller_condition in [false, true] {
+            let complete_ctx = 
ErrorContext::new(ServiceOperation("CompleteMultipartUpload"))
+                .with_caller_condition(caller_condition);
+
+            assert_eq!(
+                parse_s3_error_code(complete_ctx, "NoSuchUpload"),
+                Some((ErrorKind::Unexpected, false)),
+                "caller_condition {caller_condition}"
+            );
+            for status in [404, 200] {
+                let resp = Response::builder()
+                    .status(status)
+                    .body(Buffer::from(no_such_upload_xml))
+                    .unwrap();
+                let err = parse_error(complete_ctx, resp);
+                assert_eq!(
+                    err.kind(),
+                    ErrorKind::Unexpected,
+                    "status {status}, caller_condition {caller_condition}"
+                );
+                assert!(
+                    !err.is_temporary(),
+                    "status {status}, caller_condition {caller_condition}"
+                );
+            }
+
+            assert_eq!(
+                parse_s3_error_code(complete_ctx, "NoSuchKey"),
+                Some((ErrorKind::NotFound, false)),
+                "caller_condition {caller_condition}"
+            );
+            for status in [404, 200] {
+                let resp = Response::builder()
+                    .status(status)
+                    .body(Buffer::from(no_such_key_xml))
+                    .unwrap();
+                let err = parse_error(complete_ctx, resp);
+                assert_eq!(
+                    err.kind(),
+                    ErrorKind::NotFound,
+                    "status {status}, caller_condition {caller_condition}"
+                );
+                assert!(
+                    !err.is_temporary(),
+                    "status {status}, caller_condition {caller_condition}"
+                );
+            }
+        }
+
+        for operation in ["UploadPart", "UploadPartCopy", 
"AbortMultipartUpload"] {
+            let ctx = ErrorContext::new(ServiceOperation(operation));
+            assert_eq!(
+                parse_s3_error_code(ctx, "NoSuchUpload"),
+                None,
+                "{operation} must leave NoSuchUpload unclassified"
+            );
+            let resp = Response::builder()
+                .status(404)
+                .body(Buffer::from(no_such_upload_xml))
+                .unwrap();
+            let err = parse_error(ctx, resp);
+            assert_eq!(err.kind(), ErrorKind::NotFound, "{operation}");
+            assert!(!err.is_temporary(), "{operation}");
+        }
+    }
 }

Reply via email to