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

[Bug]: Fix unreturned sdkdiag.AppendErrorf function calls #38854

Merged
merged 10 commits into from
Aug 15, 2024

Conversation

jar-b
Copy link
Member

@jar-b jar-b commented Aug 13, 2024

Description

Fixes various calls to the sdkdiag.AppendErrorf function which are neither returned nor re-assigned to the diags variable.

Relations

Closes #38769

References

Output from Acceptance Testing

% make testacc PKG=acm TESTS=TestAccACMCertificateDataSource_
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.6 test ./internal/service/acm/... -v -count 1 -parallel 20 -run='TestAccACMCertificateDataSource_'  -timeout 360m

--- PASS: TestAccACMCertificateDataSource_tags (17.25s)
--- PASS: TestAccACMCertificateDataSource_keyTypes (18.50s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/acm        24.817s
% make testacc PKG=appstream TESTS=TestAccAppStreamStack_
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.6 test ./internal/service/appstream/... -v -count 1 -parallel 20 -run='TestAccAppStreamStack_'  -timeout 360m

--- PASS: TestAccAppStreamStack_disappears (33.89s)
--- PASS: TestAccAppStreamStack_applicationSettings_removeFromDisabled (41.20s)
--- PASS: TestAccAppStreamStack_basic (54.97s)
--- PASS: TestAccAppStreamStack_applicationSettings_removeFromEnabled (55.92s)
--- PASS: TestAccAppStreamStack_withTags (56.27s)
--- PASS: TestAccAppStreamStack_complete (56.69s)
--- PASS: TestAccAppStreamStack_streamingExperienceSettings_basic (70.81s)
--- PASS: TestAccAppStreamStack_applicationSettings_basic (71.70s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/appstream  81.569s
% make testacc PKG=ecs TESTS=TestAccECSClusterCapacityProviders_
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.6 test ./internal/service/ecs/... -v -count 1 -parallel 20 -run='TestAccECSClusterCapacityProviders_'  -timeout 360m

=== NAME  TestAccECSClusterCapacityProviders_destroy
    cluster_capacity_providers_test.go:120: Step 1/2 error: Check failed: Check 2/2 error: RegisteredContainerInstancesCount = 0, want 2
--- PASS: TestAccECSClusterCapacityProviders_defaults (47.98s)
--- PASS: TestAccECSClusterCapacityProviders_basic (48.20s)
--- PASS: TestAccECSClusterCapacityProviders_disappears (56.22s)
--- PASS: TestAccECSClusterCapacityProviders_Update_defaultStrategy (113.11s)
--- PASS: TestAccECSClusterCapacityProviders_Update_capacityProviders (113.13s)
--- FAIL: TestAccECSClusterCapacityProviders_destroy (169.06s)
FAIL
FAIL    github.com/hashicorp/terraform-provider-aws/internal/service/ecs        179.063s

Failure unrelated to this change.

% make testacc PKG=rolesanywhere TESTS=TestAccRolesAnywhereProfile_
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.6 test ./internal/service/rolesanywhere/... -v -count 1 -parallel 20 -run='TestAccRolesAnywhereProfile_'  -timeout 360m

--- PASS: TestAccRolesAnywhereProfile_disappears (16.78s)
--- PASS: TestAccRolesAnywhereProfile_enabled (46.73s)
--- PASS: TestAccRolesAnywhereProfile_tags (51.98s)
--- PASS: TestAccRolesAnywhereProfile_basic (60.46s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/rolesanywhere      66.542s
% make testacc PKG=s3 TESTS=TestAccS3BucketLifecycleConfiguration_
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.6 test ./internal/service/s3/... -v -count 1 -parallel 20 -run='TestAccS3BucketLifecycleConfiguration_'  -timeout 360m

=== NAME  TestAccS3BucketLifecycleConfiguration_directoryBucket
    bucket_lifecycle_configuration_test.go:1056: Step 1/1, expected an error with pattern, no match on: Error running apply: exit status 1

        Error: creating S3 Bucket (tf-acc-test-503241382809497100--use1-az6--x-s3) Lifecycle Configuration: operation error S3: PutBucketLifecycleConfiguration, https response error StatusCode: 0, RequestID: , HostID: , request send failed, Put "https://s3express-control.aws-global.amazonaws.com/tf-acc-test-503241382809497100--use1-az6--x-s3?lifecycle=": dial tcp: lookup s3express-control.aws-global.amazonaws.com: no such host

          with aws_s3_bucket_lifecycle_configuration.test,
          on terraform_plugin_test.tf line 35, in resource "aws_s3_bucket_lifecycle_configuration" "test":
          35: resource "aws_s3_bucket_lifecycle_configuration" "test" {

--- FAIL: TestAccS3BucketLifecycleConfiguration_directoryBucket (13.50s)
=== CONT  TestAccS3BucketLifecycleConfiguration_Filter_ObjectSizeGreaterThanZero
--- PASS: TestAccS3BucketLifecycleConfiguration_migrate_noChange (71.76s)
=== CONT  TestAccS3BucketLifecycleConfiguration_Filter_ObjectSizeRange
--- PASS: TestAccS3BucketLifecycleConfiguration_migrate_withChange (71.80s)
=== CONT  TestAccS3BucketLifecycleConfiguration_Filter_ObjectSizeLessThan
--- PASS: TestAccS3BucketLifecycleConfiguration_TransitionStorageClassOnly_intelligentTiering (76.54s)
=== CONT  TestAccS3BucketLifecycleConfiguration_filterWithPrefix
--- PASS: TestAccS3BucketLifecycleConfiguration_EmptyFilter_NonCurrentVersions (86.73s)
=== CONT  TestAccS3BucketLifecycleConfiguration_Filter_ObjectSizeGreaterThan
--- PASS: TestAccS3BucketLifecycleConfiguration_RuleExpiration_emptyBlock (87.53s)
=== CONT  TestAccS3BucketLifecycleConfiguration_multipleRules
--- PASS: TestAccS3BucketLifecycleConfiguration_Filter_ObjectSizeRangeAndPrefix (87.60s)
=== CONT  TestAccS3BucketLifecycleConfiguration_disappears
--- PASS: TestAccS3BucketLifecycleConfiguration_prefix (87.60s)
=== CONT  TestAccS3BucketLifecycleConfiguration_disableRule
--- PASS: TestAccS3BucketLifecycleConfiguration_basic (87.64s)
--- PASS: TestAccS3BucketLifecycleConfiguration_Filter_Tag (87.64s)
--- PASS: TestAccS3BucketLifecycleConfiguration_Filter_ObjectSizeGreaterThanZero (74.16s)
--- PASS: TestAccS3BucketLifecycleConfiguration_nonCurrentVersionExpiration (87.69s)
--- PASS: TestAccS3BucketLifecycleConfiguration_TransitionDate_standardIa (87.72s)
--- PASS: TestAccS3BucketLifecycleConfiguration_TransitionZeroDays_intelligentTiering (87.74s)
--- PASS: TestAccS3BucketLifecycleConfiguration_TransitionDate_intelligentTiering (87.76s)
--- PASS: TestAccS3BucketLifecycleConfiguration_multipleRules_noFilterOrPrefix (87.78s)
--- PASS: TestAccS3BucketLifecycleConfiguration_nonCurrentVersionTransition (88.18s)
--- PASS: TestAccS3BucketLifecycleConfiguration_Update_filterWithAndToFilterWithPrefix (130.30s)
--- PASS: TestAccS3BucketLifecycleConfiguration_Filter_ObjectSizeRange (64.26s)
--- PASS: TestAccS3BucketLifecycleConfiguration_disappears (48.44s)
--- PASS: TestAccS3BucketLifecycleConfiguration_Filter_ObjectSizeLessThan (64.29s)
--- PASS: TestAccS3BucketLifecycleConfiguration_Filter_ObjectSizeGreaterThan (65.50s)
--- PASS: TestAccS3BucketLifecycleConfiguration_multipleRules (66.14s)
--- PASS: TestAccS3BucketLifecycleConfiguration_ruleAbortIncompleteMultipartUpload (158.96s)
--- PASS: TestAccS3BucketLifecycleConfiguration_RuleExpiration_expireMarkerOnly (159.03s)
--- PASS: TestAccS3BucketLifecycleConfiguration_filterWithPrefix (136.76s)
--- PASS: TestAccS3BucketLifecycleConfiguration_TransitionUpdateBetweenDaysAndDate_intelligentTiering (214.88s)
--- PASS: TestAccS3BucketLifecycleConfiguration_disableRule (184.62s)
FAIL
FAIL    github.com/hashicorp/terraform-provider-aws/internal/service/s3 278.401s

Failure unrelated to this change.

Copy link

Community Note

Voting for Prioritization

  • Please vote on this pull request by adding a 👍 reaction to the original post to help the community and maintainers prioritize this pull request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

For Submitters

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • For new resources and data sources, use skaff to generate scaffolding with comments detailing common expectations.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@github-actions github-actions bot added service/s3 Issues and PRs that pertain to the s3 service. service/ecs Issues and PRs that pertain to the ecs service. service/acm Issues and PRs that pertain to the acm service. service/appstream Issues and PRs that pertain to the appstream service. service/fms Issues and PRs that pertain to the fms service. service/rolesanywhere Issues and PRs that pertain to the rolesanywhere service. service/controltower Issues and PRs that pertain to the controltower service. prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. labels Aug 13, 2024
@jar-b jar-b added the bug Addresses a defect in current functionality. label Aug 14, 2024
@jar-b jar-b changed the title [TechDebt]: Fix unreturned sdkdiag.AppendErrorf function calls [Bug]: Fix unreturned sdkdiag.AppendErrorf function calls Aug 14, 2024
@jar-b jar-b marked this pull request as ready for review August 14, 2024 14:49
@jar-b jar-b requested a review from a team as a code owner August 14, 2024 14:49
Copy link
Contributor

@ewbankkit ewbankkit left a comment

Choose a reason for hiding this comment

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

LGTM 🚀.

Can we add a semgrep rule to trap future occurrences?

Copy link

Thank you for your contribution! 🚀

A new usage of AWS SDK for Go V1 was detected. Please prefer AWS SDK for Go V2 for all net-new services. If this is an enhancement or bug fix to an existing AWS SDK Go V1 based resource, this comment can be safely ignored.

For additional information refer to the AWS SDK for Go Versions page in the contributor guide.

@jar-b
Copy link
Member Author

jar-b commented Aug 14, 2024

Added a new rule. Running against main (without the fixes from this branch):

% semgrep --config .ci/.semgrep.yml ./internal/service/
<snip>

    internal/service/s3/bucket_lifecycle_configuration.go
   ❯❯❱ ci.unreturned-sdkdiag-AppendErrorf
          Calls to `sdkdiag.AppendErrorf()` should be returned or set to the `diags` variable

          292┆ if err != nil {
          293┆   sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket Lifecycle Configuration (%s) create:
               %s", d.Id(), err)
          294┆ }
            ⋮┆----------------------------------------
          390┆ if err != nil {
          391┆   sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket Lifecycle Configuration (%s) update:
               %s", d.Id(), err)
          392┆ }

┌──────────────┐
│ Scan Summary │
└──────────────┘
Some files were skipped or only partially analyzed.
  Scan was limited to files tracked by git.
  Partially scanned: 8 files only partially analyzed due to parsing or internal Semgrep errors

Ran 34 rules on 6254 files: 12 findings.

The same rule run on this branch produces no findings.

```console
% make testacc PKG=acm TESTS=TestAccACMCertificateDataSource_
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.6 test ./internal/service/acm/... -v -count 1 -parallel 20 -run='TestAccACMCertificateDataSource_'  -timeout 360m

--- PASS: TestAccACMCertificateDataSource_tags (17.25s)
--- PASS: TestAccACMCertificateDataSource_keyTypes (18.50s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/acm        24.817s
```
```console
% make testacc PKG=appstream TESTS=TestAccAppStreamStack_
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.6 test ./internal/service/appstream/... -v -count 1 -parallel 20 -run='TestAccAppStreamStack_'  -timeout 360m

--- PASS: TestAccAppStreamStack_disappears (33.89s)
--- PASS: TestAccAppStreamStack_applicationSettings_removeFromDisabled (41.20s)
--- PASS: TestAccAppStreamStack_basic (54.97s)
--- PASS: TestAccAppStreamStack_applicationSettings_removeFromEnabled (55.92s)
--- PASS: TestAccAppStreamStack_withTags (56.27s)
--- PASS: TestAccAppStreamStack_complete (56.69s)
--- PASS: TestAccAppStreamStack_streamingExperienceSettings_basic (70.81s)
--- PASS: TestAccAppStreamStack_applicationSettings_basic (71.70s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/appstream  81.569s
```
…rrorf` calls

```console
% make testacc PKG=ecs TESTS=TestAccECSClusterCapacityProviders_
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.6 test ./internal/service/ecs/... -v -count 1 -parallel 20 -run='TestAccECSClusterCapacityProviders_'  -timeout 360m

=== NAME  TestAccECSClusterCapacityProviders_destroy
    cluster_capacity_providers_test.go:120: Step 1/2 error: Check failed: Check 2/2 error: RegisteredContainerInstancesCount = 0, want 2
--- PASS: TestAccECSClusterCapacityProviders_defaults (47.98s)
--- PASS: TestAccECSClusterCapacityProviders_basic (48.20s)
--- PASS: TestAccECSClusterCapacityProviders_disappears (56.22s)
--- PASS: TestAccECSClusterCapacityProviders_Update_defaultStrategy (113.11s)
--- PASS: TestAccECSClusterCapacityProviders_Update_capacityProviders (113.13s)
--- FAIL: TestAccECSClusterCapacityProviders_destroy (169.06s)
FAIL
FAIL    github.com/hashicorp/terraform-provider-aws/internal/service/ecs        179.063s
```

Failure unrelated to this change.
```console
% make testacc PKG=rolesanywhere TESTS=TestAccRolesAnywhereProfile_
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.6 test ./internal/service/rolesanywhere/... -v -count 1 -parallel 20 -run='TestAccRolesAnywhereProfile_'  -timeout 360m

--- PASS: TestAccRolesAnywhereProfile_disappears (16.78s)
--- PASS: TestAccRolesAnywhereProfile_enabled (46.73s)
--- PASS: TestAccRolesAnywhereProfile_tags (51.98s)
--- PASS: TestAccRolesAnywhereProfile_basic (60.46s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/rolesanywhere      66.542s
```
…ndErrorf` calls

```console
% make testacc PKG=s3 TESTS=TestAccS3BucketLifecycleConfiguration_
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.6 test ./internal/service/s3/... -v -count 1 -parallel 20 -run='TestAccS3BucketLifecycleConfiguration_'  -timeout 360m

=== NAME  TestAccS3BucketLifecycleConfiguration_directoryBucket
    bucket_lifecycle_configuration_test.go:1056: Step 1/1, expected an error with pattern, no match on: Error running apply: exit status 1

        Error: creating S3 Bucket (tf-acc-test-503241382809497100--use1-az6--x-s3) Lifecycle Configuration: operation error S3: PutBucketLifecycleConfiguration, https response error StatusCode: 0, RequestID: , HostID: , request send failed, Put "https://s3express-control.aws-global.amazonaws.com/tf-acc-test-503241382809497100--use1-az6--x-s3?lifecycle=": dial tcp: lookup s3express-control.aws-global.amazonaws.com: no such host

          with aws_s3_bucket_lifecycle_configuration.test,
          on terraform_plugin_test.tf line 35, in resource "aws_s3_bucket_lifecycle_configuration" "test":
          35: resource "aws_s3_bucket_lifecycle_configuration" "test" {

--- FAIL: TestAccS3BucketLifecycleConfiguration_directoryBucket (13.50s)
=== CONT  TestAccS3BucketLifecycleConfiguration_Filter_ObjectSizeGreaterThanZero
--- PASS: TestAccS3BucketLifecycleConfiguration_migrate_noChange (71.76s)
=== CONT  TestAccS3BucketLifecycleConfiguration_Filter_ObjectSizeRange
--- PASS: TestAccS3BucketLifecycleConfiguration_migrate_withChange (71.80s)
=== CONT  TestAccS3BucketLifecycleConfiguration_Filter_ObjectSizeLessThan
--- PASS: TestAccS3BucketLifecycleConfiguration_TransitionStorageClassOnly_intelligentTiering (76.54s)
=== CONT  TestAccS3BucketLifecycleConfiguration_filterWithPrefix
--- PASS: TestAccS3BucketLifecycleConfiguration_EmptyFilter_NonCurrentVersions (86.73s)
=== CONT  TestAccS3BucketLifecycleConfiguration_Filter_ObjectSizeGreaterThan
--- PASS: TestAccS3BucketLifecycleConfiguration_RuleExpiration_emptyBlock (87.53s)
=== CONT  TestAccS3BucketLifecycleConfiguration_multipleRules
--- PASS: TestAccS3BucketLifecycleConfiguration_Filter_ObjectSizeRangeAndPrefix (87.60s)
=== CONT  TestAccS3BucketLifecycleConfiguration_disappears
--- PASS: TestAccS3BucketLifecycleConfiguration_prefix (87.60s)
=== CONT  TestAccS3BucketLifecycleConfiguration_disableRule
--- PASS: TestAccS3BucketLifecycleConfiguration_basic (87.64s)
--- PASS: TestAccS3BucketLifecycleConfiguration_Filter_Tag (87.64s)
--- PASS: TestAccS3BucketLifecycleConfiguration_Filter_ObjectSizeGreaterThanZero (74.16s)
--- PASS: TestAccS3BucketLifecycleConfiguration_nonCurrentVersionExpiration (87.69s)
--- PASS: TestAccS3BucketLifecycleConfiguration_TransitionDate_standardIa (87.72s)
--- PASS: TestAccS3BucketLifecycleConfiguration_TransitionZeroDays_intelligentTiering (87.74s)
--- PASS: TestAccS3BucketLifecycleConfiguration_TransitionDate_intelligentTiering (87.76s)
--- PASS: TestAccS3BucketLifecycleConfiguration_multipleRules_noFilterOrPrefix (87.78s)
--- PASS: TestAccS3BucketLifecycleConfiguration_nonCurrentVersionTransition (88.18s)
--- PASS: TestAccS3BucketLifecycleConfiguration_Update_filterWithAndToFilterWithPrefix (130.30s)
--- PASS: TestAccS3BucketLifecycleConfiguration_Filter_ObjectSizeRange (64.26s)
--- PASS: TestAccS3BucketLifecycleConfiguration_disappears (48.44s)
--- PASS: TestAccS3BucketLifecycleConfiguration_Filter_ObjectSizeLessThan (64.29s)
--- PASS: TestAccS3BucketLifecycleConfiguration_Filter_ObjectSizeGreaterThan (65.50s)
--- PASS: TestAccS3BucketLifecycleConfiguration_multipleRules (66.14s)
--- PASS: TestAccS3BucketLifecycleConfiguration_ruleAbortIncompleteMultipartUpload (158.96s)
--- PASS: TestAccS3BucketLifecycleConfiguration_RuleExpiration_expireMarkerOnly (159.03s)
--- PASS: TestAccS3BucketLifecycleConfiguration_filterWithPrefix (136.76s)
--- PASS: TestAccS3BucketLifecycleConfiguration_TransitionUpdateBetweenDaysAndDate_intelligentTiering (214.88s)
--- PASS: TestAccS3BucketLifecycleConfiguration_disableRule (184.62s)
FAIL
FAIL    github.com/hashicorp/terraform-provider-aws/internal/service/s3 278.401s
```

Failure unrelated to this change.
Running this rule against `main` (without the fixes from this branch):

```console
% semgrep --config .ci/.semgrep.yml ./internal/service/
<snip>

    internal/service/s3/bucket_lifecycle_configuration.go
   ❯❯❱ ci.unreturned-sdkdiag-AppendErrorf
          Calls to `sdkdiag.AppendErrorf()` should be returned or set to the `diags` variable

          292┆ if err != nil {
          293┆   sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket Lifecycle Configuration (%s) create:
               %s", d.Id(), err)
          294┆ }
            ⋮┆----------------------------------------
          390┆ if err != nil {
          391┆   sdkdiag.AppendErrorf(diags, "waiting for S3 Bucket Lifecycle Configuration (%s) update:
               %s", d.Id(), err)
          392┆ }

┌──────────────┐
│ Scan Summary │
└──────────────┘
Some files were skipped or only partially analyzed.
  Scan was limited to files tracked by git.
  Partially scanned: 8 files only partially analyzed due to parsing or internal Semgrep errors

Ran 34 rules on 6254 files: 12 findings.
```

The same rule run on this branch produces no findings.
@jar-b jar-b merged commit 7b440b8 into main Aug 15, 2024
33 checks passed
@jar-b jar-b deleted the td-appenderrorf-return branch August 15, 2024 14:26
@github-actions github-actions bot added this to the v5.63.0 milestone Aug 15, 2024
terraform-aws-provider bot pushed a commit that referenced this pull request Aug 15, 2024
Copy link

This functionality has been released in v5.63.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions github-actions bot removed the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Aug 15, 2024
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 15, 2024
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. service/acm Issues and PRs that pertain to the acm service. service/appstream Issues and PRs that pertain to the appstream service. service/controltower Issues and PRs that pertain to the controltower service. service/ecs Issues and PRs that pertain to the ecs service. service/fms Issues and PRs that pertain to the fms service. service/rolesanywhere Issues and PRs that pertain to the rolesanywhere service. service/s3 Issues and PRs that pertain to the s3 service.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TechDebt]: Investigate unreturned sdkdiags.AppendErrorf function calls
2 participants