Skip to content

Commit

Permalink
fix "return nil on err" cases and enable related linter (dagger#9199)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
sipsma authored Dec 13, 2024
1 parent 4539614 commit 63636db
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion core/modulesource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion engine/sources/httpdns/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions modules/golangci/lint-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ linters:
- unparam
- whitespace
- gomodguard
- nilerr

issues:
exclude-rules:
Expand Down

0 comments on commit 63636db

Please sign in to comment.