Skip to content

Commit

Permalink
Fix generated SDK errors to use pointer receivers (#3207)
Browse files Browse the repository at this point in the history
Fixes the generated SDK API errors to use pointer function receivers
instead of value. This fixes potential confusion writing code and not
casting to the correct type. The SDK will always return the API error as
a pointer, not value.

Code that did type assertions from the operation's returned error to the
value type would never be satisfied. Leading to errors being missed.
Changing the function receiver to a pointer prevents this error.
Highlighting it in code bases.
  • Loading branch information
jasdel committed Mar 30, 2020
1 parent 323bf04 commit 5ccf17b
Show file tree
Hide file tree
Showing 202 changed files with 14,139 additions and 14,136 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
* Update SDK's `go-jmespath` dependency to latest tagged version `0.3.0` ([#3205](https://github.com/aws/aws-sdk-go/pull/3205))

### SDK Bugs
* Fix generated SDK errors to use pointer receivers
* Fixes the generated SDK API errors to use pointer function receivers instead of value. This fixes potential confusion writing code and not casting to the correct type. The SDK will always return the API error as a pointer, not value.
* Code that did type assertions from the operation's returned error to the value type would never be satisfied. Leading to errors being missed. Changing the function receiver to a pointer prevents this error. Highlighting it in code bases.
24 changes: 12 additions & 12 deletions private/model/api/codegentest/service/restjsonservice/api.go

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

24 changes: 12 additions & 12 deletions private/model/api/codegentest/service/restxmlservice/api.go

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

24 changes: 12 additions & 12 deletions private/model/api/codegentest/service/rpcservice/api.go

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

12 changes: 6 additions & 6 deletions private/model/api/shape.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,12 +814,12 @@ func newError{{ $.ShapeName }}(v protocol.ResponseMetadata) error {
}
// Code returns the exception type name.
func (s {{ $.ShapeName }}) Code() string {
func (s *{{ $.ShapeName }}) Code() string {
return "{{ $.ErrorName }}"
}
// Message returns the exception's message.
func (s {{ $.ShapeName }}) Message() string {
func (s *{{ $.ShapeName }}) Message() string {
{{- if index $.MemberRefs "Message_" }}
if s.Message_ != nil {
return *s.Message_
Expand All @@ -829,11 +829,11 @@ func (s {{ $.ShapeName }}) Message() string {
}
// OrigErr always returns nil, satisfies awserr.Error interface.
func (s {{ $.ShapeName }}) OrigErr() error {
func (s *{{ $.ShapeName }}) OrigErr() error {
return nil
}
func (s {{ $.ShapeName }}) Error() string {
func (s *{{ $.ShapeName }}) Error() string {
{{- if or (and (eq (len $.MemberRefs) 1) (not (index $.MemberRefs "Message_"))) (gt (len $.MemberRefs) 1) }}
return fmt.Sprintf("%s: %s\n%s", s.Code(), s.Message(), s.String())
{{- else }}
Expand All @@ -842,12 +842,12 @@ func (s {{ $.ShapeName }}) Error() string {
}
// Status code returns the HTTP status code for the request's response error.
func (s {{ $.ShapeName }}) StatusCode() int {
func (s *{{ $.ShapeName }}) StatusCode() int {
return s.RespMetadata.StatusCode
}
// RequestID returns the service's response RequestID for request.
func (s {{ $.ShapeName }}) RequestID() string {
func (s *{{ $.ShapeName }}) RequestID() string {
return s.RespMetadata.RequestID
}
`))
Expand Down

0 comments on commit 5ccf17b

Please sign in to comment.