Skip to content

Commit

Permalink
Breakfix revert SQS string error constants (#5101)
Browse files Browse the repository at this point in the history
  • Loading branch information
isaiahvita committed Dec 8, 2023
1 parent b417ac5 commit 87f2688
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 26 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
94 changes: 91 additions & 3 deletions private/model/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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": {
Expand Down
44 changes: 22 additions & 22 deletions service/sqs/errors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 87f2688

Please sign in to comment.