From 338d3c89ad7d91bed48b52a3fa8d4c6269f10397 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 30 Jul 2024 17:14:36 -0700 Subject: [PATCH] ci: add errorlint 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 --- .golangci.yml | 1 + capability_linux.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 07064a0..d775aad 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -3,3 +3,4 @@ linters: - unconvert - unparam - gofumpt + - errorlint diff --git a/capability_linux.go b/capability_linux.go index 994bb13..b2cfdb2 100644 --- a/capability_linux.go +++ b/capability_linux.go @@ -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 } @@ -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 }