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

Tech debt: Prefer (*awserr.Error) instead of (*awserr.Error).Code() / (*awserr.Error).Message() in fmt.Errorf() #24745

Merged
merged 22 commits into from
May 11, 2022

Conversation

ewbankkit
Copy link
Contributor

@ewbankkit ewbankkit commented May 11, 2022

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" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Closes #12987.
Closes #8349.

Fixes:

% semgrep --config .semgrep.yml 
Scanning 3906 files.
  100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████|3906/3906 tasks

Findings:

  internal/service/autoscaling/notification.go 
     fmt-Errorf-awserr-Error-Code
        Prefer `err` with `%w` format verb instead of `err.Code()` or `err.Message()`

        174┆ return fmt.Errorf("Error creating Autoscaling Group Notification for Group %s, error: \"%s\", code: \"%s\"", *a, awsErr.Message(), awsErr.Code())


  internal/service/ec2/ebs_volume_attachment.go 
     fmt-Errorf-awserr-Error-Code
        Prefer `err` with `%w` format verb instead of `err.Code()` or `err.Message()`

        120┆ return fmt.Errorf("Error attaching volume (%s) to instance (%s), message: \"%s\", code: \"%s\"",
        121┆ 	vID, iID, awsErr.Message(), awsErr.Code())
          ⋮┆----------------------------------------
        253┆ return nil, "failed", fmt.Errorf("code: %s, message: %s", awsErr.Code(), awsErr.Message())

Some files were skipped.
  Scan was limited to files tracked by git.
  Scan skipped: 1593 files matching .semgrepignore patterns
  For a full list of skipped files, run semgrep with the --verbose flag.

Ran 1 rule on 3906 files: 3 findings.

@ewbankkit
Copy link
Contributor Author

ewbankkit commented May 11, 2022

% make testacc TESTARGS='-run=TestAccEC2EBSVolumeAttachment_' PKG=ec2 ACCTEST_PARALLELISM=2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ec2/... -v -count 1 -parallel 2  -run=TestAccEC2EBSVolumeAttachment_ -timeout 180m
=== RUN   TestAccEC2EBSVolumeAttachment_basic
=== PAUSE TestAccEC2EBSVolumeAttachment_basic
=== RUN   TestAccEC2EBSVolumeAttachment_skipDestroy
=== PAUSE TestAccEC2EBSVolumeAttachment_skipDestroy
=== RUN   TestAccEC2EBSVolumeAttachment_attachStopped
=== PAUSE TestAccEC2EBSVolumeAttachment_attachStopped
=== RUN   TestAccEC2EBSVolumeAttachment_update
=== PAUSE TestAccEC2EBSVolumeAttachment_update
=== RUN   TestAccEC2EBSVolumeAttachment_disappears
=== PAUSE TestAccEC2EBSVolumeAttachment_disappears
=== RUN   TestAccEC2EBSVolumeAttachment_stopInstance
=== PAUSE TestAccEC2EBSVolumeAttachment_stopInstance
=== CONT  TestAccEC2EBSVolumeAttachment_basic
=== CONT  TestAccEC2EBSVolumeAttachment_update
--- PASS: TestAccEC2EBSVolumeAttachment_basic (149.98s)
=== CONT  TestAccEC2EBSVolumeAttachment_attachStopped
--- PASS: TestAccEC2EBSVolumeAttachment_update (169.61s)
=== CONT  TestAccEC2EBSVolumeAttachment_stopInstance
--- PASS: TestAccEC2EBSVolumeAttachment_stopInstance (118.10s)
=== CONT  TestAccEC2EBSVolumeAttachment_skipDestroy
--- PASS: TestAccEC2EBSVolumeAttachment_attachStopped (148.64s)
=== CONT  TestAccEC2EBSVolumeAttachment_disappears
--- PASS: TestAccEC2EBSVolumeAttachment_skipDestroy (128.86s)
--- PASS: TestAccEC2EBSVolumeAttachment_disappears (149.68s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	452.807s
% make testacc TESTARGS='-run=TestAccAutoScalingNotification_' PKG=autoscaling ACCTEST_PARALLELISM=2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/autoscaling/... -v -count 1 -parallel 2  -run=TestAccAutoScalingNotification_ -timeout 180m
=== RUN   TestAccAutoScalingNotification_ASG_basic
=== PAUSE TestAccAutoScalingNotification_ASG_basic
=== RUN   TestAccAutoScalingNotification_ASG_update
=== PAUSE TestAccAutoScalingNotification_ASG_update
=== RUN   TestAccAutoScalingNotification_ASG_pagination
=== PAUSE TestAccAutoScalingNotification_ASG_pagination
=== CONT  TestAccAutoScalingNotification_ASG_basic
=== CONT  TestAccAutoScalingNotification_ASG_pagination
--- PASS: TestAccAutoScalingNotification_ASG_pagination (100.59s)
=== CONT  TestAccAutoScalingNotification_ASG_update
--- PASS: TestAccAutoScalingNotification_ASG_basic (172.79s)
--- PASS: TestAccAutoScalingNotification_ASG_update (317.14s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/autoscaling	421.691s
% make testacc TESTARGS='-run=TestAccEC2EBSVolume_' PKG=ec2 ACCTEST_PARALLELISM=2 
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ec2/... -v -count 1 -parallel 2  -run=TestAccEC2EBSVolume_ -timeout 180m
=== RUN   TestAccEC2EBSVolume_basic
=== PAUSE TestAccEC2EBSVolume_basic
=== RUN   TestAccEC2EBSVolume_updateAttachedEBSVolume
=== PAUSE TestAccEC2EBSVolume_updateAttachedEBSVolume
=== RUN   TestAccEC2EBSVolume_updateSize
=== PAUSE TestAccEC2EBSVolume_updateSize
=== RUN   TestAccEC2EBSVolume_updateType
=== PAUSE TestAccEC2EBSVolume_updateType
=== RUN   TestAccEC2EBSVolume_UpdateIops_io1
=== PAUSE TestAccEC2EBSVolume_UpdateIops_io1
=== RUN   TestAccEC2EBSVolume_UpdateIops_io2
=== PAUSE TestAccEC2EBSVolume_UpdateIops_io2
=== RUN   TestAccEC2EBSVolume_kmsKey
=== PAUSE TestAccEC2EBSVolume_kmsKey
=== RUN   TestAccEC2EBSVolume_noIops
=== PAUSE TestAccEC2EBSVolume_noIops
=== RUN   TestAccEC2EBSVolume_invalidIopsForType
=== PAUSE TestAccEC2EBSVolume_invalidIopsForType
=== RUN   TestAccEC2EBSVolume_invalidThroughputForType
=== PAUSE TestAccEC2EBSVolume_invalidThroughputForType
=== RUN   TestAccEC2EBSVolume_withTags
=== PAUSE TestAccEC2EBSVolume_withTags
=== RUN   TestAccEC2EBSVolume_multiAttach
=== PAUSE TestAccEC2EBSVolume_multiAttach
=== RUN   TestAccEC2EBSVolume_outpost
=== PAUSE TestAccEC2EBSVolume_outpost
=== RUN   TestAccEC2EBSVolume_GP3_basic
=== PAUSE TestAccEC2EBSVolume_GP3_basic
=== RUN   TestAccEC2EBSVolume_GP3_iops
=== PAUSE TestAccEC2EBSVolume_GP3_iops
=== RUN   TestAccEC2EBSVolume_GP3_throughput
=== PAUSE TestAccEC2EBSVolume_GP3_throughput
=== RUN   TestAccEC2EBSVolume_gp3ToGP2
=== PAUSE TestAccEC2EBSVolume_gp3ToGP2
=== RUN   TestAccEC2EBSVolume_snapshotID
=== PAUSE TestAccEC2EBSVolume_snapshotID
=== RUN   TestAccEC2EBSVolume_snapshotIDAndSize
=== PAUSE TestAccEC2EBSVolume_snapshotIDAndSize
=== RUN   TestAccEC2EBSVolume_disappears
=== PAUSE TestAccEC2EBSVolume_disappears
=== CONT  TestAccEC2EBSVolume_basic
=== CONT  TestAccEC2EBSVolume_withTags
--- PASS: TestAccEC2EBSVolume_withTags (42.44s)
=== CONT  TestAccEC2EBSVolume_UpdateIops_io2
--- PASS: TestAccEC2EBSVolume_basic (42.75s)
=== CONT  TestAccEC2EBSVolume_invalidThroughputForType
--- PASS: TestAccEC2EBSVolume_invalidThroughputForType (3.11s)
=== CONT  TestAccEC2EBSVolume_invalidIopsForType
--- PASS: TestAccEC2EBSVolume_invalidIopsForType (2.74s)
=== CONT  TestAccEC2EBSVolume_noIops
--- PASS: TestAccEC2EBSVolume_noIops (41.68s)
=== CONT  TestAccEC2EBSVolume_kmsKey
--- PASS: TestAccEC2EBSVolume_UpdateIops_io2 (70.21s)
=== CONT  TestAccEC2EBSVolume_GP3_throughput
=== CONT  TestAccEC2EBSVolume_disappears
--- PASS: TestAccEC2EBSVolume_kmsKey (47.87s)
--- PASS: TestAccEC2EBSVolume_disappears (38.57s)
=== CONT  TestAccEC2EBSVolume_snapshotIDAndSize
--- PASS: TestAccEC2EBSVolume_GP3_throughput (69.30s)
=== CONT  TestAccEC2EBSVolume_snapshotID
--- PASS: TestAccEC2EBSVolume_snapshotIDAndSize (82.60s)
=== CONT  TestAccEC2EBSVolume_gp3ToGP2
--- PASS: TestAccEC2EBSVolume_snapshotID (83.49s)
=== CONT  TestAccEC2EBSVolume_GP3_basic
--- PASS: TestAccEC2EBSVolume_GP3_basic (45.42s)
=== CONT  TestAccEC2EBSVolume_GP3_iops
--- PASS: TestAccEC2EBSVolume_gp3ToGP2 (74.79s)
=== CONT  TestAccEC2EBSVolume_outpost
    acctest.go:1308: skipping since no Outposts found
--- SKIP: TestAccEC2EBSVolume_outpost (0.51s)
=== CONT  TestAccEC2EBSVolume_updateType
--- PASS: TestAccEC2EBSVolume_GP3_iops (72.82s)
=== CONT  TestAccEC2EBSVolume_UpdateIops_io1
--- PASS: TestAccEC2EBSVolume_updateType (72.56s)
=== CONT  TestAccEC2EBSVolume_multiAttach
--- PASS: TestAccEC2EBSVolume_multiAttach (43.64s)
=== CONT  TestAccEC2EBSVolume_updateSize
--- PASS: TestAccEC2EBSVolume_UpdateIops_io1 (72.99s)
=== CONT  TestAccEC2EBSVolume_updateAttachedEBSVolume
--- PASS: TestAccEC2EBSVolume_updateSize (70.75s)
--- PASS: TestAccEC2EBSVolume_updateAttachedEBSVolume (255.61s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	721.564s

@github-actions github-actions bot added linter Pertains to changes to or issues with the various linters. service/autoscaling Issues and PRs that pertain to the autoscaling service. service/ec2ebs Issues and PRs that pertain to the ec2ebs service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. size/XL Managed by automation to categorize the size of a PR. labels May 11, 2022
ewbankkit added 11 commits May 11, 2022 11:52
Acceptance test output:

% make testacc TESTARGS='-run=TestAccEC2EBSVolume_basic' PKG=ec2 ACCTEST_PARALLELISM=2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ec2/... -v -count 1 -parallel 2  -run=TestAccEC2EBSVolume_basic -timeout 180m
=== RUN   TestAccEC2EBSVolume_basic
=== PAUSE TestAccEC2EBSVolume_basic
=== CONT  TestAccEC2EBSVolume_basic
--- PASS: TestAccEC2EBSVolume_basic (27.11s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	32.393s
Acceptance test output:

% make testacc TESTARGS='-run=TestAccEC2EBSVolume_basic' PKG=ec2 ACCTEST_PARALLELISM=2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ec2/... -v -count 1 -parallel 2  -run=TestAccEC2EBSVolume_basic -timeout 180m
=== RUN   TestAccEC2EBSVolume_basic
=== PAUSE TestAccEC2EBSVolume_basic
=== CONT  TestAccEC2EBSVolume_basic
--- PASS: TestAccEC2EBSVolume_basic (38.11s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	42.182s
Acceptance test output:

% make testacc TESTARGS='-run=TestAccEC2EBSVolume_basic' PKG=ec2 ACCTEST_PARALLELISM=2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ec2/... -v -count 1 -parallel 2  -run=TestAccEC2EBSVolume_basic -timeout 180m
=== RUN   TestAccEC2EBSVolume_basic
=== PAUSE TestAccEC2EBSVolume_basic
=== CONT  TestAccEC2EBSVolume_basic
--- PASS: TestAccEC2EBSVolume_basic (38.70s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	43.220s
Acceptance test output:

% make testacc TESTARGS='-run=TestAccEC2EBSVolume_updateAttachedEBSVolume' PKG=ec2 ACCTEST_PARALLELISM=2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/ec2/... -v -count 1 -parallel 2  -run=TestAccEC2EBSVolume_updateAttachedEBSVolume -timeout 180m
=== RUN   TestAccEC2EBSVolume_updateAttachedEBSVolume
=== PAUSE TestAccEC2EBSVolume_updateAttachedEBSVolume
=== CONT  TestAccEC2EBSVolume_updateAttachedEBSVolume
--- PASS: TestAccEC2EBSVolume_updateAttachedEBSVolume (206.21s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/ec2	211.877s
@github-actions github-actions bot added the documentation Introduces or discusses updates to documentation. label May 11, 2022
@ewbankkit
Copy link
Contributor Author

% make golangci-lint
==> Checking source code with golangci-lint...

@ewbankkit ewbankkit merged commit 0a4f39d into main May 11, 2022
@ewbankkit ewbankkit deleted the td-fmt-Errorf-no-Code-or-Message branch May 11, 2022 19:38
@github-actions github-actions bot added this to the v4.14.0 milestone May 11, 2022
github-actions bot pushed a commit that referenced this pull request May 11, 2022
@github-actions
Copy link

This functionality has been released in v4.14.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
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 Jun 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. linter Pertains to changes to or issues with the various linters. service/autoscaling Issues and PRs that pertain to the autoscaling service. service/ec2ebs Issues and PRs that pertain to the ec2ebs service. 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
2 participants