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

chore: directly handle ignored errs and nolint intentionally ignored errs #2993

Merged
merged 49 commits into from
Oct 2, 2024

Conversation

mkcp
Copy link
Contributor

@mkcp mkcp commented Sep 12, 2024

Description

This PR relies on enabling additional errcheck rules on golangci-lint and revive to find errors that we've failed to handle or propagate. The most common cases are defers, which we handle by joining them with a err named return (a bit too much magic imo, but is the most airtight in case of a panic). Ideally we handle a specific error that wasn't passed up, but sometimes we have to change the function signature. Lastly, there's times where propagating the error isn't viable or useful and we'll have to log out.

Unfortunately the linter will flag when there's unused nolint checks, so we can't mark intentionally ignored errors with //nolint:errcheck until the actual PR that introduces the linter checks into main.

Rules changes are:

diff --git a/.golangci.yaml b/.golangci.yaml
index 6423df77..18b3f0f1 100644
--- a/.golangci.yaml
+++ b/.golangci.yaml
@@ -59,6 +59,7 @@ linters-settings:
   testifylint:
     enable-all: true
   errcheck:
+    check-blank: true
     check-type-assertions: true
     exclude-functions:
       - (*github.com/spf13/cobra.Command).Help
@@ -68,6 +69,7 @@ linters-settings:
 issues:
   # Revive rules that are disabled by default.
   include:
+    - EXC0001
     - EXC0012
     - EXC0013
     - EXC0014

Related Issue

Blocks #3053
Relates to #2953

Checklist before merging

@mkcp mkcp self-assigned this Sep 12, 2024
Copy link

netlify bot commented Sep 12, 2024

Deploy Preview for zarf-docs canceled.

Name Link
🔨 Latest commit 1c69af4
🔍 Latest deploy log https://app.netlify.com/sites/zarf-docs/deploys/66fd84d1cee7220008194d33

Copy link

codecov bot commented Sep 12, 2024

Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
… to nolint ignore them

Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
…anic

Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
…gnore it

Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
src/cmd/initialize.go Outdated Show resolved Hide resolved
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
…w comments

Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
src/cmd/destroy.go Outdated Show resolved Hide resolved
src/cmd/dev.go Outdated Show resolved Hide resolved
src/cmd/initialize.go Outdated Show resolved Hide resolved
src/cmd/package.go Show resolved Hide resolved
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
…f loop

Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
Signed-off-by: Kit Patella <kit@defenseunicorns.com>
@mkcp mkcp mentioned this pull request Oct 1, 2024
2 tasks
src/pkg/utils/auth.go Outdated Show resolved Hide resolved
_, err := f.WriteString(start)
_, err = f.WriteString(start)
require.NoError(t, err)
err = f.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we want to check the err here within the defer block

Signed-off-by: Kit Patella <kit@defenseunicorns.com>
@mkcp mkcp added this pull request to the merge queue Oct 2, 2024
Merged via the queue into main with commit 28c296b Oct 2, 2024
26 checks passed
@mkcp mkcp deleted the mkcp/2949-errcheck-linter branch October 2, 2024 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants