From 87f2688a108037b955757f47e6be8fe016eb03d1 Mon Sep 17 00:00:00 2001 From: Isaiah Vita <82135527+isaiahvita@users.noreply.github.com> Date: Fri, 8 Dec 2023 13:23:17 -0800 Subject: [PATCH] Breakfix revert SQS string error constants (#5101) --- CHANGELOG_PENDING.md | 2 + private/model/api/api.go | 94 ++++++++++++++++++- .../awsquerycompatible_test.go | 3 +- service/sqs/errors.go | 44 ++++----- 4 files changed, 117 insertions(+), 26 deletions(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 8a1927a39ca..9b45174d68d 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -1,4 +1,6 @@ ### SDK Features +* `service/sqs`: BREAKFIX: Revert SQS error constants to original state + * Values for SQS error constants were incorrectly changed. This reverts them back. ### SDK Enhancements diff --git a/private/model/api/api.go b/private/model/api/api.go index e888979cd1f..f2e30429406 100644 --- a/private/model/api/api.go +++ b/private/model/api/api.go @@ -95,11 +95,11 @@ type Metadata struct { EndpointsID string ServiceID string - NoResolveEndpoint bool + NoResolveEndpoint bool AWSQueryCompatible *awsQueryCompatible } -type awsQueryCompatible struct {} +type awsQueryCompatible struct{} // ProtocolSettings define how the SDK should handle requests in the context // of of a protocol. @@ -950,12 +950,100 @@ const ( {{- end }} `)) +// A tplAPIErrors is the top level template for the API +var tplAPIErrorsSQS = template.Must(template.New("api").Parse(` +const ( + {{- range $_, $s := $.ShapeListErrors }} + + // {{ $s.ErrorCodeName }} for service response error code + {{- if eq $s.ErrorCodeName "ErrCodeBatchEntryIdsNotDistinct" }} + // "AWS.SimpleQueueService.BatchEntryIdsNotDistinct". + {{- else if eq $s.ErrorCodeName "ErrCodeBatchRequestTooLong" }} + // "AWS.SimpleQueueService.BatchRequestTooLong". + {{- else if eq $s.ErrorCodeName "ErrCodeEmptyBatchRequest" }} + // "AWS.SimpleQueueService.EmptyBatchRequest". + {{- else if eq $s.ErrorCodeName "ErrCodeInvalidBatchEntryId" }} + // "AWS.SimpleQueueService.InvalidBatchEntryId". + {{- else if eq $s.ErrorCodeName "ErrCodeMessageNotInflight" }} + // "AWS.SimpleQueueService.MessageNotInflight". + {{- else if eq $s.ErrorCodeName "ErrCodePurgeQueueInProgress" }} + // "AWS.SimpleQueueService.PurgeQueueInProgress". + {{- else if eq $s.ErrorCodeName "ErrCodeQueueDeletedRecently" }} + // "AWS.SimpleQueueService.QueueDeletedRecently". + {{- else if eq $s.ErrorCodeName "ErrCodeQueueDoesNotExist" }} + // "AWS.SimpleQueueService.NonExistentQueue". + {{- else if eq $s.ErrorCodeName "ErrCodeTooManyEntriesInBatchRequest" }} + // "AWS.SimpleQueueService.TooManyEntriesInBatchRequest". + {{- else if eq $s.ErrorCodeName "ErrCodeUnsupportedOperation" }} + // "AWS.SimpleQueueService.UnsupportedOperation". + {{- else if eq $s.ErrorCodeName "ErrCodeQueueNameExists" }} + // "QueueAlreadyExists". + {{- else }} + // {{ printf "%q" $s.ErrorName }}. + {{- end }} + {{ if $s.Docstring -}} + // + {{ $s.Docstring }} + {{ end -}} + + + {{- if eq $s.ErrorCodeName "ErrCodeBatchEntryIdsNotDistinct" -}} + {{ $s.ErrorCodeName }} = "AWS.SimpleQueueService.BatchEntryIdsNotDistinct" + {{- else if eq $s.ErrorCodeName "ErrCodeBatchRequestTooLong" -}} + {{ $s.ErrorCodeName }} = "AWS.SimpleQueueService.BatchRequestTooLong" + {{- else if eq $s.ErrorCodeName "ErrCodeEmptyBatchRequest" -}} + {{ $s.ErrorCodeName }} = "AWS.SimpleQueueService.EmptyBatchRequest" + {{- else if eq $s.ErrorCodeName "ErrCodeInvalidBatchEntryId" -}} + {{ $s.ErrorCodeName }} = "AWS.SimpleQueueService.InvalidBatchEntryId" + {{- else if eq $s.ErrorCodeName "ErrCodeMessageNotInflight" -}} + {{ $s.ErrorCodeName }} = "AWS.SimpleQueueService.MessageNotInflight" + {{- else if eq $s.ErrorCodeName "ErrCodePurgeQueueInProgress" -}} + {{ $s.ErrorCodeName }} = "AWS.SimpleQueueService.PurgeQueueInProgress" + {{- else if eq $s.ErrorCodeName "ErrCodeQueueDeletedRecently" -}} + {{ $s.ErrorCodeName }} = "AWS.SimpleQueueService.QueueDeletedRecently" + {{- else if eq $s.ErrorCodeName "ErrCodeQueueDoesNotExist" -}} + {{ $s.ErrorCodeName }} = "AWS.SimpleQueueService.NonExistentQueue" + {{- else if eq $s.ErrorCodeName "ErrCodeTooManyEntriesInBatchRequest" -}} + {{ $s.ErrorCodeName }} = "AWS.SimpleQueueService.TooManyEntriesInBatchRequest" + {{- else if eq $s.ErrorCodeName "ErrCodeUnsupportedOperation" -}} + {{ $s.ErrorCodeName }} = "AWS.SimpleQueueService.UnsupportedOperation" + {{- else if eq $s.ErrorCodeName "ErrCodeQueueNameExists" -}} + {{ $s.ErrorCodeName }} = "QueueAlreadyExists" + {{- else -}} + {{ $s.ErrorCodeName }} = {{ printf "%q" $s.ErrorName }} + {{- end -}} + {{- end }} +) + +{{- if $.WithGeneratedTypedErrors }} + {{- $_ := $.AddSDKImport "private/protocol" }} + + var exceptionFromCode = map[string]func(protocol.ResponseMetadata)error { + {{- range $_, $s := $.ShapeListErrors }} + "{{ $s.ErrorName }}": newError{{ $s.ShapeName }}, + {{- end }} + } + {{- if .Metadata.AWSQueryCompatible }} + var queryExceptionFromCode = map[string]func(protocol.ResponseMetadata, string)error { + {{- range $_, $s := $.ShapeListErrors }} + "{{ $s.ErrorName }}": newQueryCompatibleError{{ $s.ShapeName }}, + {{- end }} + } + {{- end }} +{{- end }} +`)) + // APIErrorsGoCode returns the Go code for the errors.go file. func (a *API) APIErrorsGoCode() string { a.resetImports() var buf bytes.Buffer - err := tplAPIErrors.Execute(&buf, a) + var err error + if a.Metadata.ServiceID == "SQS" { + err = tplAPIErrorsSQS.Execute(&buf, a) + } else { + err = tplAPIErrors.Execute(&buf, a) + } if err != nil { panic(err) diff --git a/private/model/api/codegentest/service/awsquerycompatible/awsquerycompatible_test.go b/private/model/api/codegentest/service/awsquerycompatible/awsquerycompatible_test.go index 20a81ca21f4..bae01215dd3 100644 --- a/private/model/api/codegentest/service/awsquerycompatible/awsquerycompatible_test.go +++ b/private/model/api/codegentest/service/awsquerycompatible/awsquerycompatible_test.go @@ -16,6 +16,7 @@ import ( "github.com/aws/aws-sdk-go/aws/corehandlers" "github.com/aws/aws-sdk-go/aws/request" "github.com/aws/aws-sdk-go/awstesting/unit" + "github.com/aws/aws-sdk-go/service/sqs" ) func TestAWSQuery(t *testing.T) { @@ -31,7 +32,7 @@ func TestAWSQuery(t *testing.T) { "when header is present": { statusCode: 400, responseBody: strings.NewReader(`{"__type":"com.amazonaws.awsquerycompatible#QueueDeletedRecently", "message":"Some user-visible message"}`), - expectErrorCode: "AWS.SimpleQueueService.QueueDeletedRecently", + expectErrorCode: sqs.ErrCodeQueueDeletedRecently, headers: map[string]string{"x-amzn-query-error": "AWS.SimpleQueueService.QueueDeletedRecently;Sender"}, }, "for unmodeled error code": { diff --git a/service/sqs/errors.go b/service/sqs/errors.go index de1e86dca22..8c1ff8d2504 100644 --- a/service/sqs/errors.go +++ b/service/sqs/errors.go @@ -9,22 +9,22 @@ import ( const ( // ErrCodeBatchEntryIdsNotDistinct for service response error code - // "BatchEntryIdsNotDistinct". + // "AWS.SimpleQueueService.BatchEntryIdsNotDistinct". // // Two or more batch entries in the request have the same Id. - ErrCodeBatchEntryIdsNotDistinct = "BatchEntryIdsNotDistinct" + ErrCodeBatchEntryIdsNotDistinct = "AWS.SimpleQueueService.BatchEntryIdsNotDistinct" // ErrCodeBatchRequestTooLong for service response error code - // "BatchRequestTooLong". + // "AWS.SimpleQueueService.BatchRequestTooLong". // // The length of all the messages put together is more than the limit. - ErrCodeBatchRequestTooLong = "BatchRequestTooLong" + ErrCodeBatchRequestTooLong = "AWS.SimpleQueueService.BatchRequestTooLong" // ErrCodeEmptyBatchRequest for service response error code - // "EmptyBatchRequest". + // "AWS.SimpleQueueService.EmptyBatchRequest". // // The batch request doesn't contain any entries. - ErrCodeEmptyBatchRequest = "EmptyBatchRequest" + ErrCodeEmptyBatchRequest = "AWS.SimpleQueueService.EmptyBatchRequest" // ErrCodeInvalidAddress for service response error code // "InvalidAddress". @@ -45,10 +45,10 @@ const ( ErrCodeInvalidAttributeValue = "InvalidAttributeValue" // ErrCodeInvalidBatchEntryId for service response error code - // "InvalidBatchEntryId". + // "AWS.SimpleQueueService.InvalidBatchEntryId". // // The Id of a batch entry in a batch request doesn't abide by the specification. - ErrCodeInvalidBatchEntryId = "InvalidBatchEntryId" + ErrCodeInvalidBatchEntryId = "AWS.SimpleQueueService.InvalidBatchEntryId" // ErrCodeInvalidIdFormat for service response error code // "InvalidIdFormat". @@ -119,10 +119,10 @@ const ( ErrCodeKmsThrottled = "KmsThrottled" // ErrCodeMessageNotInflight for service response error code - // "MessageNotInflight". + // "AWS.SimpleQueueService.MessageNotInflight". // // The specified message isn't in flight. - ErrCodeMessageNotInflight = "MessageNotInflight" + ErrCodeMessageNotInflight = "AWS.SimpleQueueService.MessageNotInflight" // ErrCodeOverLimit for service response error code // "OverLimit". @@ -134,33 +134,33 @@ const ( ErrCodeOverLimit = "OverLimit" // ErrCodePurgeQueueInProgress for service response error code - // "PurgeQueueInProgress". + // "AWS.SimpleQueueService.PurgeQueueInProgress". // // Indicates that the specified queue previously received a PurgeQueue request // within the last 60 seconds (the time it can take to delete the messages in // the queue). - ErrCodePurgeQueueInProgress = "PurgeQueueInProgress" + ErrCodePurgeQueueInProgress = "AWS.SimpleQueueService.PurgeQueueInProgress" // ErrCodeQueueDeletedRecently for service response error code - // "QueueDeletedRecently". + // "AWS.SimpleQueueService.QueueDeletedRecently". // // You must wait 60 seconds after deleting a queue before you can create another // queue with the same name. - ErrCodeQueueDeletedRecently = "QueueDeletedRecently" + ErrCodeQueueDeletedRecently = "AWS.SimpleQueueService.QueueDeletedRecently" // ErrCodeQueueDoesNotExist for service response error code - // "QueueDoesNotExist". + // "AWS.SimpleQueueService.NonExistentQueue". // // The specified queue doesn't exist. - ErrCodeQueueDoesNotExist = "QueueDoesNotExist" + ErrCodeQueueDoesNotExist = "AWS.SimpleQueueService.NonExistentQueue" // ErrCodeQueueNameExists for service response error code - // "QueueNameExists". + // "QueueAlreadyExists". // // A queue with this name already exists. Amazon SQS returns this error only // if the request includes attributes whose values differ from those of the // existing queue. - ErrCodeQueueNameExists = "QueueNameExists" + ErrCodeQueueNameExists = "QueueAlreadyExists" // ErrCodeReceiptHandleIsInvalid for service response error code // "ReceiptHandleIsInvalid". @@ -193,16 +193,16 @@ const ( ErrCodeResourceNotFoundException = "ResourceNotFoundException" // ErrCodeTooManyEntriesInBatchRequest for service response error code - // "TooManyEntriesInBatchRequest". + // "AWS.SimpleQueueService.TooManyEntriesInBatchRequest". // // The batch request contains more entries than permissible. - ErrCodeTooManyEntriesInBatchRequest = "TooManyEntriesInBatchRequest" + ErrCodeTooManyEntriesInBatchRequest = "AWS.SimpleQueueService.TooManyEntriesInBatchRequest" // ErrCodeUnsupportedOperation for service response error code - // "UnsupportedOperation". + // "AWS.SimpleQueueService.UnsupportedOperation". // // Error code 400. Unsupported operation. - ErrCodeUnsupportedOperation = "UnsupportedOperation" + ErrCodeUnsupportedOperation = "AWS.SimpleQueueService.UnsupportedOperation" ) var exceptionFromCode = map[string]func(protocol.ResponseMetadata) error{