From 8bbdb93cf9d2011c535b91e3dbf9d18d00b9d739 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 20 Nov 2023 14:53:40 +0100 Subject: [PATCH] golangci-lint: enable nilerr linter cli/command/idresolver/idresolver.go:33:4: error is not nil (line 31) but it returns nil (nilerr) return id, nil ^ cli/command/idresolver/idresolver.go:45:4: error is not nil (line 43) but it returns nil (nilerr) return id, nil ^ Signed-off-by: Sebastiaan van Stijn --- .golangci.yml | 1 + cli/command/idresolver/idresolver.go | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 4b97b1d118..b7b597804a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -15,6 +15,7 @@ linters: - megacheck - misspell - nakedret + - nilerr # Detects code that returns nil even if it checks that the error is not nil. - predeclared - revive - staticcheck diff --git a/cli/command/idresolver/idresolver.go b/cli/command/idresolver/idresolver.go index 4bc2e4acab..cae4bb7339 100644 --- a/cli/command/idresolver/idresolver.go +++ b/cli/command/idresolver/idresolver.go @@ -30,7 +30,8 @@ func (r *IDResolver) get(ctx context.Context, t interface{}, id string) (string, case swarm.Node: node, _, err := r.client.NodeInspectWithRaw(ctx, id) if err != nil { - return id, nil + // TODO(thaJeztah): should error-handling be more specific, or is it ok to ignore any error? + return id, nil //nolint:nilerr // ignore nil-error being returned, as this is a best-effort. } if node.Spec.Annotations.Name != "" { return node.Spec.Annotations.Name, nil @@ -42,7 +43,8 @@ func (r *IDResolver) get(ctx context.Context, t interface{}, id string) (string, case swarm.Service: service, _, err := r.client.ServiceInspectWithRaw(ctx, id, types.ServiceInspectOptions{}) if err != nil { - return id, nil + // TODO(thaJeztah): should error-handling be more specific, or is it ok to ignore any error? + return id, nil //nolint:nilerr // ignore nil-error being returned, as this is a best-effort. } return service.Spec.Annotations.Name, nil default: