From 63636db470c718c3b99e490135990764508f8208 Mon Sep 17 00:00:00 2001 From: Erik Sipsma Date: Fri, 13 Dec 2024 12:21:56 -0800 Subject: [PATCH] fix "return nil on err" cases and enable related linter (#9199) Happened across an instance of incorrectly returning nil when err was set while working on stuff. This fixes that and enables the nilerr linter for catching these things, which revealed another occurence. As far as I can tell these haven't been actively hurting us most likely (the error cases are extremely unlikely to happen) but worth preventing these spooky typos from happening again going forward. Signed-off-by: Erik Sipsma --- core/directory.go | 2 +- core/modulesource.go | 2 +- engine/sources/httpdns/source.go | 2 +- modules/golangci/lint-config.yml | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/directory.go b/core/directory.go index 2e83960a65..2003eabd40 100644 --- a/core/directory.go +++ b/core/directory.go @@ -135,7 +135,7 @@ func (dir *Directory) SetState(ctx context.Context, st llb.State) error { buildkit.WithPassthrough(), // these spans aren't particularly interesting ) if err != nil { - return nil + return err } dir.LLB = def.ToPB() diff --git a/core/modulesource.go b/core/modulesource.go index a5d0ead971..b774059ee0 100644 --- a/core/modulesource.go +++ b/core/modulesource.go @@ -572,7 +572,7 @@ func (src *ModuleSource) ModuleConfig(ctx context.Context) (*modules.ModuleConfi configFile, err := contextDir.Self.File(ctx, filepath.Join(rootSubpath, modules.Filename)) if err != nil { // no configuration for this module yet, so no name - return nil, false, nil + return nil, false, nil //nolint:nilerr } configBytes, err := configFile.Contents(ctx) if err != nil { diff --git a/engine/sources/httpdns/source.go b/engine/sources/httpdns/source.go index 4d890f703b..9e876a8f75 100644 --- a/engine/sources/httpdns/source.go +++ b/engine/sources/httpdns/source.go @@ -162,7 +162,7 @@ func (hs *httpSourceHandler) CacheKey(ctx context.Context, g session.Group, inde uh, err := hs.urlHash() if err != nil { - return "", "", nil, false, nil + return "", "", nil, false, err } // look up metadata(previously stored headers) for that URL diff --git a/modules/golangci/lint-config.yml b/modules/golangci/lint-config.yml index ea6f772b30..02ef61aca8 100644 --- a/modules/golangci/lint-config.yml +++ b/modules/golangci/lint-config.yml @@ -27,6 +27,7 @@ linters: - unparam - whitespace - gomodguard + - nilerr issues: exclude-rules: