From f82df703022f6c325d75cc224cacecc5561f2945 Mon Sep 17 00:00:00 2001 From: Deluan Date: Fri, 30 Sep 2022 20:18:14 -0400 Subject: [PATCH] Add nilerr linter --- .golangci.yml | 1 + core/agents/agents.go | 10 +++++----- persistence/property_repository.go | 2 +- persistence/user_props_repository.go | 2 +- tests/mock_property_repo.go | 2 +- tests/mock_user_props_repo.go | 2 +- utils/cache/spread_fs.go | 2 +- 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 804b5995..ecb63342 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -20,6 +20,7 @@ linters: - govet - ineffassign - misspell + - nilerr - rowserrcheck - staticcheck - typecheck diff --git a/core/agents/agents.go b/core/agents/agents.go index edf168e6..4f50b5f0 100644 --- a/core/agents/agents.go +++ b/core/agents/agents.go @@ -54,7 +54,7 @@ func (a *Agents) GetMBID(ctx context.Context, id string, name string) (string, e mbid, err := agent.GetMBID(ctx, id, name) if mbid != "" && err == nil { log.Debug(ctx, "Got MBID", "agent", ag.AgentName(), "artist", name, "mbid", mbid, "elapsed", time.Since(start)) - return mbid, err + return mbid, nil } } return "", ErrNotFound @@ -73,7 +73,7 @@ func (a *Agents) GetURL(ctx context.Context, id, name, mbid string) (string, err url, err := agent.GetURL(ctx, id, name, mbid) if url != "" && err == nil { log.Debug(ctx, "Got External Url", "agent", ag.AgentName(), "artist", name, "url", url, "elapsed", time.Since(start)) - return url, err + return url, nil } } return "", ErrNotFound @@ -92,7 +92,7 @@ func (a *Agents) GetBiography(ctx context.Context, id, name, mbid string) (strin bio, err := agent.GetBiography(ctx, id, name, mbid) if bio != "" && err == nil { log.Debug(ctx, "Got Biography", "agent", ag.AgentName(), "artist", name, "len", len(bio), "elapsed", time.Since(start)) - return bio, err + return bio, nil } } return "", ErrNotFound @@ -134,7 +134,7 @@ func (a *Agents) GetImages(ctx context.Context, id, name, mbid string) ([]Artist images, err := agent.GetImages(ctx, id, name, mbid) if len(images) > 0 && err == nil { log.Debug(ctx, "Got Images", "agent", ag.AgentName(), "artist", name, "images", images, "elapsed", time.Since(start)) - return images, err + return images, nil } } return nil, ErrNotFound @@ -153,7 +153,7 @@ func (a *Agents) GetTopSongs(ctx context.Context, id, artistName, mbid string, c songs, err := agent.GetTopSongs(ctx, id, artistName, mbid, count) if len(songs) > 0 && err == nil { log.Debug(ctx, "Got Top Songs", "agent", ag.AgentName(), "artist", artistName, "songs", songs, "elapsed", time.Since(start)) - return songs, err + return songs, nil } } return nil, ErrNotFound diff --git a/persistence/property_repository.go b/persistence/property_repository.go index ece50305..d62cdec6 100644 --- a/persistence/property_repository.go +++ b/persistence/property_repository.go @@ -25,7 +25,7 @@ func (r propertyRepository) Put(id string, value string) error { update := Update(r.tableName).Set("value", value).Where(Eq{"id": id}) count, err := r.executeSQL(update) if err != nil { - return nil + return err } if count > 0 { return nil diff --git a/persistence/user_props_repository.go b/persistence/user_props_repository.go index 90a75bf8..1fe9c7b9 100644 --- a/persistence/user_props_repository.go +++ b/persistence/user_props_repository.go @@ -25,7 +25,7 @@ func (r userPropsRepository) Put(userId, key string, value string) error { update := Update(r.tableName).Set("value", value).Where(And{Eq{"user_id": userId}, Eq{"key": key}}) count, err := r.executeSQL(update) if err != nil { - return nil + return err } if count > 0 { return nil diff --git a/tests/mock_property_repo.go b/tests/mock_property_repo.go index be88efc1..39dec17b 100644 --- a/tests/mock_property_repo.go +++ b/tests/mock_property_repo.go @@ -53,7 +53,7 @@ func (p *MockedPropertyRepo) DefaultGet(id string, defaultValue string) (string, p.init() v, err := p.Get(id) if err != nil { - return defaultValue, nil + return defaultValue, nil //nolint:nilerr } return v, nil } diff --git a/tests/mock_user_props_repo.go b/tests/mock_user_props_repo.go index 2f8554d7..b1880c99 100644 --- a/tests/mock_user_props_repo.go +++ b/tests/mock_user_props_repo.go @@ -53,7 +53,7 @@ func (p *MockedUserPropsRepo) DefaultGet(userId, key string, defaultValue string p.init() v, err := p.Get(userId, key) if err != nil { - return defaultValue, nil + return defaultValue, nil //nolint:nilerr } return v, nil } diff --git a/utils/cache/spread_fs.go b/utils/cache/spread_fs.go index ef85e60c..281e2bfa 100644 --- a/utils/cache/spread_fs.go +++ b/utils/cache/spread_fs.go @@ -47,7 +47,7 @@ func (sfs *spreadFS) Reload(f func(key string, name string)) error { } path, err := filepath.Rel(sfs.root, absoluteFilePath) if err != nil { - return nil + return nil //nolint:nilerr } // Skip if name is not in the format XX/XX/XXXXXXXXXXXX