Skip to content
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

Fix generated SDK errors to use pointer receivers #3207

Merged
merged 3 commits into from
Mar 30, 2020

Conversation

jasdel
Copy link
Contributor

@jasdel jasdel commented Mar 13, 2020

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.

For example the following type assertion handling a service response would never work because the cloudwatchlogs.DataAlreadyAcceptedException error is returned as a pointer, not value.

resp, err := client.SomeOperationCall(params)
if err != nil {
     switch tv := err.(type)  {
     case cloudwatchlogs.DataAlreadyAcceptedException:
          log.Printf("got DataAlreadyAcceptedException error, %s", tv.String()
     default:
          log.Printf("unknown error %T, %v", err, err)
     }
}

The code would need to be written with the type assertion on the pointer value, which is what the SDK will return.

resp, err := client.SomeOperationCall(params)
if err != nil {
     switch tv := err.(type)  {
     case *cloudwatchlogs.DataAlreadyAcceptedException:
          log.Printf("got DataAlreadyAcceptedException error, %s", tv.String()
     default:
          log.Printf("unknown error %T, %v", err, err)
     }
}

@jasdel jasdel added the needs-review This issue or pull request needs review from a core team member. label Mar 13, 2020
@jasdel jasdel marked this pull request as ready for review March 13, 2020 22:47
@jasdel jasdel removed the needs-review This issue or pull request needs review from a core team member. label Mar 19, 2020
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.
@jasdel jasdel merged commit 5ccf17b into aws:master Mar 30, 2020
@jasdel jasdel deleted the fixup/ErrorGeneration branch March 30, 2020 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants