Skip to content

ci: golangci-linter add errcheck#3115

Closed
leongross wants to merge 4 commits intou-root:mainfrom
leongross:ci/errcheck
Closed

ci: golangci-linter add errcheck#3115
leongross wants to merge 4 commits intou-root:mainfrom
leongross:ci/errcheck

Conversation

@leongross
Copy link
Member

Follow-up PR on #3111, currently rebased on its branch until it is merged to circumvent merge conflicts and duplicates.

@codecov
Copy link

codecov bot commented Sep 26, 2024

Codecov Report

Attention: Patch coverage is 59.32203% with 24 lines in your changes missing coverage. Please review.

Project coverage is 60.52%. Comparing base (a620c4f) to head (623fd60).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3115      +/-   ##
==========================================
- Coverage   60.54%   60.52%   -0.02%     
==========================================
  Files         598      598              
  Lines       39885    39889       +4     
==========================================
- Hits        24147    24143       -4     
- Misses      15738    15746       +8     
Flag Coverage Δ
.-amd64 90.69% <ø> (ø)
cmds/...-amd64 53.06% <60.46%> (+<0.01%) ⬆️
integration/generic-tests/...-amd64 19.82% <ø> (ø)
integration/generic-tests/...-arm 11.63% <ø> (ø)
integration/generic-tests/...-arm64 16.38% <ø> (ø)
integration/gotests/...-amd64 63.16% <70.21%> (-0.01%) ⬇️
integration/gotests/...-arm 64.17% <70.21%> (+0.08%) ⬆️
integration/gotests/...-arm64 64.20% <70.21%> (-0.01%) ⬇️
pkg/...-amd64 60.27% <12.50%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
everything 65.51% <66.00%> (-0.03%) ⬇️
cmds/exp 33.21% <22.22%> (-0.01%) ⬇️

@leongross leongross force-pushed the ci/errcheck branch 3 times, most recently from f601c90 to 7c25401 Compare September 26, 2024 18:25
@leongross leongross changed the title ci/errcheck ci: golangci-linter add errcheck Sep 26, 2024
@leongross leongross marked this pull request as draft September 26, 2024 18:26
Copy link
Member

@rminnich rminnich left a comment

Choose a reason for hiding this comment

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

I think golangci-lint is failing badly here, it is unaware of how flag.Parse works.

This needs to be rethought in many places.

@rminnich rminnich added the Awaiting author Waiting for new changes or feedback for author. label Sep 28, 2024
@leongross leongross force-pushed the ci/errcheck branch 2 times, most recently from 1dbd814 to 44b4a69 Compare October 2, 2024 17:30
add linter option 'unparam' to ci

Signed-off-by: leongross <leon.gross@9elements.com>
* fix unparam issues, remove unused error returns
* fix changed tests when no error is returned anymore
* add TODOs and //nolint:unparam tags for future rework/refactoring

Signed-off-by: leongross <leon.gross@9elements.com>
Signed-off-by: leongross <leon.gross@9elements.com>
@leongross leongross force-pushed the ci/errcheck branch 7 times, most recently from 9f74632 to 52843d9 Compare March 1, 2025 17:50
Comment on lines +226 to +228
if err := handle.SetSocketReceiveBufferSize(bufSize, true); err != nil {
return cmd, fmt.Errorf("parseFlags: %w", err)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This causes the unit test for ip to fail:

 ip_linux_test.go:136: unexpected error: parseFlags: operation not permitted
--- FAIL: TestParseFlags (0.00s)
    --- PASS: TestParseFlags/no_args (0.00s)
    --- PASS: TestParseFlags/inet4 (0.00s)
    --- PASS: TestParseFlags/inet6 (0.00s)
    --- PASS: TestParseFlags/mpls (0.00s)
    --- PASS: TestParseFlags/bridge (0.00s)
    --- PASS: TestParseFlags/link (0.00s)
    --- PASS: TestParseFlags/family (0.00s)
    --- PASS: TestParseFlags/family_inet6 (0.00s)
    --- PASS: TestParseFlags/family_err (0.00s)
    --- PASS: TestParseFlags/resolve (0.00s)
    --- PASS: TestParseFlags/color (0.00s)
    --- FAIL: TestParseFlags/rcvBuf (0.00s

In this case, the SetSocketReceiveBufferSize function error is just not checked. It seems that running this with non-root permissions fails, but since the error is not checked, we don't catch this error.

Comment on lines +51 to +52
t.Errorf("got %v, want nil", err)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

The test for PCI fail for the cases 2,3,4:

=== RUN   TestRun
=== RUN   TestRun/switch_hexdump_case_1
=== RUN   TestRun/switch_hexdump_case_2
    pci_linux_test.go:51: got permission denied, want nil
=== RUN   TestRun/switch_hexdump_case_3
    pci_linux_test.go:51: got permission denied, want nil
=== RUN   TestRun/switch_hexdump_case_4
    pci_linux_test.go:51: got permission denied, want nil
=== RUN   TestRun/readJSON_true,_without_error
=== RUN   TestRun/readJSON_true,_error_in_os.ReadFile
=== RUN   TestRun/readJSON_true,_error_in_json.Unmarshal
=== RUN   TestRun/dumpJSON
=== RUN   TestRun/invoke_registers
--- FAIL: TestRun (0.03s)

Again, permission denied errors indicate that we should move this to vmtest root permissioned integration tests.

Comment on lines +181 to +183
if err := session.Run("echo hello u-root"); err != nil {
t.Fatalf("can't run command: %v", err)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Uncovers unhandled error:

=== RUN   TestSessionRun
2025/03/03 14:44:54 127.0.0.1:41516 logged in with key SHA256:fzAJZugrckV2ucFAxumbs7eIMsDcar11KOUKojV/4D0
2025/03/03 14:44:54 Request exec
2025/03/03 14:44:54 Executing non-PTY command zsh [-c echo hello u-root]
2025/03/03 14:44:54 Exit status 0
    sshd_test.go:182: can't run command: EOF
--- FAIL: TestSessionRun (0.13s)
FAIL
FAIL	github.com/u-root/u-root/cmds/core/sshd	0.157s
FAIL

Signed-off-by: leongross <leon.gross@9elements.com>
@leongross
Copy link
Member Author

Closing this for now. Reworking the error strategies in u-root should follow a systematic approach that we define (e.g. when we use nolint directives etc). We should define an easy-to-follow pattern so that we do not have to discuss this on each and every PR.

Until we establish this I close this PR.

@leongross leongross closed this Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Awaiting author Waiting for new changes or feedback for author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants