Skip to content

Fix DeleteObjects to throw DeleteObjectsException instead of AmazonS3Exception #3839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: aws-sdk-net-v3.7-development
Choose a base branch
from

Conversation

AlexDaines
Copy link
Contributor

Description

Added UnmarshallException method override to DeleteObjectsResponseUnmarshaller to ensure that all DeleteObjects operation failures consistently throw DeleteObjectsException instead of the generic AmazonS3Exception.
The fix creates a DeleteObjectsResponse containing structured error information and wraps it in a DeleteObjectsException, preserving all error details (ErrorCode, RequestId, StatusCode) while providing the expected exception type.

Motivation and Context

Fixes issue #3828 reported inconsistent exception handling for DeleteObjects operations.

Testing

  • Tested with invalid keys (too long), confirming DeleteObjectsException is now thrown
  • Verified that exception contains proper error information in Response.DeleteErrors collection
  • Validated that ErrorCode, RequestId, and StatusCode are properly preserved

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed

License

  • I confirm that this pull request can be released under the Apache 2 license

@AlexDaines AlexDaines marked this pull request as ready for review May 22, 2025 17:47
@AlexDaines AlexDaines requested a review from normj May 22, 2025 17:47

// For standard S3 error responses (like KeyTooLongError), create a DeleteObjectsException
// with the error information wrapped in a DeleteObjectsResponse
var errorResponse = S3ErrorResponseUnmarshaller.Instance.Unmarshall(context);
Copy link

@grsw92 grsw92 May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlexDaines does this solution guarantee that object under valid key gets deleted when sent along with invalid key in a single DeleteObjectsRequest?

@dscpinheiro dscpinheiro added v4 v3 and removed v4 labels May 25, 2025
@dscpinheiro
Copy link
Contributor

Discussed offline, this should target V4 instead as it's not a blocking issue in V3.

@dscpinheiro dscpinheiro requested a review from peterrsongg June 3, 2025 17:35
@peterrsongg peterrsongg changed the base branch from aws-sdk-net-v3.7-development to development June 3, 2025 19:48
@peterrsongg peterrsongg changed the base branch from development to aws-sdk-net-v3.7-development June 3, 2025 19:49
Copy link
Contributor

@peterrsongg peterrsongg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionally, looks good. Just needs an integ test and needs to target the development branch.

/// <param name="innerException"></param>
/// <param name="statusCode"></param>
/// <returns></returns>
public override AmazonServiceException UnmarshallException(XmlUnmarshallerContext context, Exception innerException, HttpStatusCode statusCode)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an integration test that would trigger this code path and asserts that a DeleteObjectsException is thrown?

var errorResponse = S3ErrorResponseUnmarshaller.Instance.Unmarshall(context);

// Create a DeleteObjectsResponse containing the error information
var deleteObjectsResponse = new DeleteObjectsResponse();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are now implementing unmarshallException properly can we remove this logic here as part of this PR?

https://github.com/aws/aws-sdk-net/blob/main/sdk/src/Services/S3/Custom/Internal/AmazonS3ResponseHandler.cs#L100-L107

It seems useless since UnmarshallException will be called first and the sdk will throw an exception.

{
var responseBodyBytes = context.GetResponseBodyBytes();

// First, try to parse as a standard DeleteObjects response (for cases where S3 returns mixed results)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain what you mean by "mixed results"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants