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

internal/keyvaluetags: Use Go 1.13 error wrapping with UpdateTags errors #10670

Merged
merged 2 commits into from
Oct 30, 2019

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Oct 29, 2019

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

Reference: https://blog.golang.org/go1.13-errors
Reference: #10411
Reference: https://github.com/terraform-providers/terraform-provider-aws/blob/c64f19eebf6e1c5d31374b02def9226b2945f52c/aws/resource_aws_subnet.go#L146-L151

Release note for CHANGELOG:

NONE

Found via acceptance testing prior to an actual release:

--- FAIL: TestAccAWSEMRCluster_basic (19.03s)
    testing.go:615: Step 0 error: errors during apply:
        
        Error: error adding tags: error tagging resource (subnet-04c4088b2c7f3aa42): InvalidSubnetID.NotFound: The subnet ID 'subnet-04c4088b2c7f3aa42' does not exist
        	status code: 400, request id: 2dafd3b1-ffef-49f9-98e0-1ede0726e8bb

Any logic attempting to check the returned AWS Go SDK error code/message from keyvaluetags package UpdateTags usage will not work since the errors are currently wrapped by value, which was the only option in Go 1.12 and earlier. Go 1.13 introduced the new %w verb for fmt.Errorf() for wrapping errors, which allows downstream logic to check wrapped error types via errors.As().

Updated via:

$ make gen

bflad added 2 commits October 29, 2019 19:21
Reference: https://blog.golang.org/go1.13-errors
Reference: #10411

Found via acceptance testing prior to an actual release:

```
--- FAIL: TestAccAWSEMRCluster_basic (19.03s)
    testing.go:615: Step 0 error: errors during apply:

        Error: error adding tags: error tagging resource (subnet-04c4088b2c7f3aa42): InvalidSubnetID.NotFound: The subnet ID 'subnet-04c4088b2c7f3aa42' does not exist
        	status code: 400, request id: 2dafd3b1-ffef-49f9-98e0-1ede0726e8bb
```

Any logic attempting to check the returned AWS Go SDK error code/message from `keyvaluetags` package `UpdateTags` usage will not work since the errors are currently wrapped by value, which was the only option in Go 1.12 and earlier. Go 1.13 introduced the new `%w` verb for `fmt.Errorf()` for wrapping errors, which allows downstream logic to check wrapped error types via `errors.As()`.

Updated via:

```console
$ make gen
```
@bflad bflad added bug Addresses a defect in current functionality. provider Pertains to the provider itself, rather than any interaction with AWS. labels Oct 29, 2019
@bflad bflad added this to the v2.34.0 milestone Oct 29, 2019
@bflad bflad requested a review from a team October 29, 2019 23:39
@ghost ghost added size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Oct 29, 2019
bflad added a commit to hashicorp/aws-sdk-go-base that referenced this pull request Oct 30, 2019
…ng OrigErr() panic

Reference: hashicorp/terraform-provider-aws#10670

This was originally to just add unit testing to match testing added to the Terraform AWS Provider codebase, but discovered and fixed a panic condition in `IsAWSErrExtended()`.

In the future these functions will be updated to support Go 1.13 error wrapping via `errors.As()` so we can easily add error context without losing the error type checking, however this is waiting for github.com/hashicorp/terraform to begin releases via Go 1.13.
Copy link
Contributor

@aeschright aeschright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⭐️ 🐑 🚀 ❗️

@bflad bflad merged commit 0bbe681 into master Oct 30, 2019
@bflad bflad deleted the b-isAwsErr-wrapped-errors branch October 30, 2019 19:37
@ghost
Copy link

ghost commented Mar 29, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. provider Pertains to the provider itself, rather than any interaction with AWS. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants