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

awsproviderlint: New Check: Prefer (*awserr.Error) instead of (*awserr.Error).Code() / (*awserr.Error).Message() in fmt.Errorf() #12987

Closed
breathingdust opened this issue Apr 24, 2020 · 2 comments · Fixed by #24745
Labels
linter Pertains to changes to or issues with the various linters. provider Pertains to the provider itself, rather than any interaction with AWS. technical-debt Addresses areas of the codebase that need refactoring or redesign.

Comments

@breathingdust
Copy link
Member

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue 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 issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

The AWS Go SDK provides a good String() implementation of errors including the ErrorCode, ErrorMessage, and request ID for troubleshooting with AWS Support. We should avoid trimming out useful bits from these error messages by referencing Code(), Message(), etc. and instead simplify to just referencing the error object itself.

Flagged Code

fmt.Errorf("AWS error oh no: %s", err.Code())
fmt.Errorf("AWS error oh no: %s: %s", err.Code(), err.Message())

Passing Code

fmt.Errorf("AWS error oh no: %w", err)
@breathingdust breathingdust added technical-debt Addresses areas of the codebase that need refactoring or redesign. provider Pertains to the provider itself, rather than any interaction with AWS. labels Apr 24, 2020
@bflad
Copy link
Contributor

bflad commented Sep 8, 2020

Inexact (would need to do type checking with go/analysis) but covers this case well, a potential semgrep rule:

  - id: fmt-Errorf-awserr-Error-Code
    languages: [go]
    message: Prefer `err` with `%w` format verb instead of `err.Code()` or `err.Message()`
    paths:
      exclude:
        - vendor/
      include:
        - aws/
    patterns:
      - pattern-either:
        - pattern: fmt.Errorf(..., $ERR.Code(), ...)
        - pattern: fmt.Errorf(..., $ERR.Message(), ...)
    severity: WARNING

@github-actions
Copy link

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 have found a problem that seems similar to this, 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 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
linter Pertains to changes to or issues with the various linters. provider Pertains to the provider itself, rather than any interaction with AWS. technical-debt Addresses areas of the codebase that need refactoring or redesign.
Projects
None yet
2 participants