Skip to content

Commit

Permalink
ci: add errorlint
Browse files Browse the repository at this point in the history
With the added linter, it complains like this:

> capability_linux.go:349:22: type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint)

In fact, errors from syscall.Syscall6 used by prctl are bare Errno
values. This means there is no need for a type assertion, so let's
remove it:

	> - if errno, ok := err.(syscall.Errno); ok && errno == syscall.EINVAL {
	> + if err == syscall.EINVAL {

With that change, we're still getting error from the linter, a bit
different one:

> capability_linux.go:349:9: comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint)

So, we still need to silence it, by adding a nolint annotation.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Jul 31, 2024
1 parent cf3b5c1 commit 66c4524
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ linters:
- unconvert
- unparam
- gofumpt
- errorlint
4 changes: 2 additions & 2 deletions capability_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func (c *capsV3) Apply(kind CapType) (err error) {
err = prctl(syscall.PR_CAPBSET_DROP, uintptr(i), 0, 0, 0)
if err != nil {
// Ignore EINVAL since the capability may not be supported in this system.
if errno, ok := err.(syscall.Errno); ok && errno == syscall.EINVAL {
if err == syscall.EINVAL { //nolint:errorlint // Errors from syscall are bare.
err = nil
continue
}
Expand All @@ -372,7 +372,7 @@ func (c *capsV3) Apply(kind CapType) (err error) {
err = prctl(pr_CAP_AMBIENT, action, uintptr(i), 0, 0)
if err != nil {
// Ignore EINVAL as not supported on kernels before 4.3
if errno, ok := err.(syscall.Errno); ok && errno == syscall.EINVAL {
if err == syscall.EINVAL { //nolint:errorlint // Errors from syscall are bare.
err = nil
continue
}
Expand Down

0 comments on commit 66c4524

Please sign in to comment.