From ba5a08fbe430c7930ad2227785226200adecd20c Mon Sep 17 00:00:00 2001 From: Aaron Todd Date: Mon, 12 Jun 2023 16:27:50 -0400 Subject: [PATCH] fix: S3 HeadObject NotFound error never being returned (#2139) --- .../d9de6f3dd7c146c9966648ecda1fa2a8.json | 8 ++++ .../S3HeadObjectCustomizations.java | 45 ------------------- ...mithy.go.codegen.integration.GoIntegration | 1 - service/s3/api_op_HeadObject.go | 19 ++------ service/s3/deserializers.go | 3 ++ 5 files changed, 15 insertions(+), 61 deletions(-) create mode 100644 .changelog/d9de6f3dd7c146c9966648ecda1fa2a8.json delete mode 100644 codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/S3HeadObjectCustomizations.java diff --git a/.changelog/d9de6f3dd7c146c9966648ecda1fa2a8.json b/.changelog/d9de6f3dd7c146c9966648ecda1fa2a8.json new file mode 100644 index 00000000000..d639cd67818 --- /dev/null +++ b/.changelog/d9de6f3dd7c146c9966648ecda1fa2a8.json @@ -0,0 +1,8 @@ +{ + "id": "d9de6f3d-d7c1-46c9-9666-48ecda1fa2a8", + "type": "bugfix", + "description": "Fix HeadObject to return types.Nound when an object does not exist. Fixes [2084](https://github.com/aws/aws-sdk-go-v2/issues/2084)", + "modules": [ + "service/s3" + ] +} diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/S3HeadObjectCustomizations.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/S3HeadObjectCustomizations.java deleted file mode 100644 index 15959b10ba9..00000000000 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/S3HeadObjectCustomizations.java +++ /dev/null @@ -1,45 +0,0 @@ -package software.amazon.smithy.aws.go.codegen.customization; - -import software.amazon.smithy.go.codegen.GoSettings; -import software.amazon.smithy.go.codegen.integration.GoIntegration; -import software.amazon.smithy.model.Model; -import software.amazon.smithy.model.knowledge.TopDownIndex; -import software.amazon.smithy.model.shapes.OperationShape; -import software.amazon.smithy.model.shapes.ServiceShape; -import software.amazon.smithy.model.shapes.ShapeId; - -/** - * This integration removes incorrectly modeled S3 `NoSuchKey` error for HeadObject operation. - * Related to aws/aws-sdk-go#1208 - */ -public class S3HeadObjectCustomizations implements GoIntegration { - @Override - public byte getOrder() { - return 127; - } - - @Override - public Model preprocessModel( - Model model, GoSettings settings - ) { - ServiceShape service = model.expectShape(settings.getService(), ServiceShape.class); - if (!S3ModelUtils.isServiceS3(model, service)) { - return model; - } - - for (OperationShape operationShape: TopDownIndex.of(model).getContainedOperations(service)) { - if (operationShape.getId().getName(service).equalsIgnoreCase("HeadObject")) { - Model.Builder modelBuilder = model.toBuilder(); - OperationShape.Builder builder = operationShape.toBuilder(); - // clear all errors associated with 'HeadObject' operation aws/aws-sdk-go#1208 - builder.clearErrors(); - - // remove old operation shape and add the updated shape to model - return modelBuilder.removeShape(operationShape.getId()).addShape(builder.build()).build(); - } - } - return model; - } - - // returns true if service is s3 -} diff --git a/codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration b/codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration index aeb2f3f61ad..dd8f88327a1 100644 --- a/codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration +++ b/codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration @@ -32,7 +32,6 @@ software.amazon.smithy.aws.go.codegen.customization.S3AcceptEncodingGzip software.amazon.smithy.aws.go.codegen.customization.KinesisCustomizations software.amazon.smithy.aws.go.codegen.customization.S3ErrorWith200Status software.amazon.smithy.aws.go.codegen.customization.Route53Customizations -software.amazon.smithy.aws.go.codegen.customization.S3HeadObjectCustomizations software.amazon.smithy.aws.go.codegen.customization.PresignURLAutoFill software.amazon.smithy.aws.go.codegen.customization.S3ExportInternalFeatures software.amazon.smithy.aws.go.codegen.customization.S3ControlEndpointResolver diff --git a/service/s3/api_op_HeadObject.go b/service/s3/api_op_HeadObject.go index 0ac66893b49..a6321a34390 100644 --- a/service/s3/api_op_HeadObject.go +++ b/service/s3/api_op_HeadObject.go @@ -10,7 +10,6 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/signer/v4" s3cust "github.com/aws/aws-sdk-go-v2/service/s3/internal/customizations" "github.com/aws/aws-sdk-go-v2/service/s3/types" - smithy "github.com/aws/smithy-go" "github.com/aws/smithy-go/middleware" smithytime "github.com/aws/smithy-go/time" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -604,13 +603,8 @@ func objectExistsStateRetryable(ctx context.Context, input *HeadObjectInput, out } if err != nil { - var apiErr smithy.APIError - ok := errors.As(err, &apiErr) - if !ok { - return false, fmt.Errorf("expected err to be of type smithy.APIError, got %w", err) - } - - if "NotFound" == apiErr.ErrorCode() { + var errorType *types.NotFound + if errors.As(err, &errorType) { return true, nil } } @@ -759,13 +753,8 @@ func (w *ObjectNotExistsWaiter) WaitForOutput(ctx context.Context, params *HeadO func objectNotExistsStateRetryable(ctx context.Context, input *HeadObjectInput, output *HeadObjectOutput, err error) (bool, error) { if err != nil { - var apiErr smithy.APIError - ok := errors.As(err, &apiErr) - if !ok { - return false, fmt.Errorf("expected err to be of type smithy.APIError, got %w", err) - } - - if "NotFound" == apiErr.ErrorCode() { + var errorType *types.NotFound + if errors.As(err, &errorType) { return false, nil } } diff --git a/service/s3/deserializers.go b/service/s3/deserializers.go index 995d909cf8c..f45cf19c5d3 100644 --- a/service/s3/deserializers.go +++ b/service/s3/deserializers.go @@ -6827,6 +6827,9 @@ func awsRestxml_deserializeOpErrorHeadObject(response *smithyhttp.Response, meta } errorBody.Seek(0, io.SeekStart) switch { + case strings.EqualFold("NotFound", errorCode): + return awsRestxml_deserializeErrorNotFound(response, errorBody) + default: genericError := &smithy.GenericAPIError{ Code: errorCode,