From 4228af271a507e80e5c30c9ca8c25e8f01e108cb Mon Sep 17 00:00:00 2001 From: Dominic Evans Date: Wed, 8 Sep 2021 10:37:45 +0100 Subject: [PATCH] fix: enable nilerr linter and fix iferr checks nilerr finds code which returns nil even though it checks that error is not nil. This flagged up a few incorrect checks in some of our packet encoder/decoders, so fix those. --- .golangci.yml | 1 + alter_configs_response.go | 4 ++-- describe_configs_response.go | 6 +++--- logger_test.go | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 09e5c468c..77494dccb 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -57,6 +57,7 @@ linters: # - ineffassign # - misspell # - nakedret + - nilerr # - scopelint - staticcheck - structcheck diff --git a/alter_configs_response.go b/alter_configs_response.go index cfb6369ac..84cd86c72 100644 --- a/alter_configs_response.go +++ b/alter_configs_response.go @@ -61,12 +61,12 @@ func (a *AlterConfigsResourceResponse) encode(pe packetEncoder) error { pe.putInt16(a.ErrorCode) err := pe.putString(a.ErrorMsg) if err != nil { - return nil + return err } pe.putInt8(int8(a.Type)) err = pe.putString(a.Name) if err != nil { - return nil + return err } return nil } diff --git a/describe_configs_response.go b/describe_configs_response.go index 928f5a52a..4968f4854 100644 --- a/describe_configs_response.go +++ b/describe_configs_response.go @@ -308,19 +308,19 @@ func (c *ConfigSynonym) encode(pe packetEncoder, version int16) (err error) { func (c *ConfigSynonym) decode(pd packetDecoder, version int16) error { name, err := pd.getString() if err != nil { - return nil + return err } c.ConfigName = name value, err := pd.getString() if err != nil { - return nil + return err } c.ConfigValue = value source, err := pd.getInt8() if err != nil { - return nil + return err } c.Source = ConfigSource(source) return nil diff --git a/logger_test.go b/logger_test.go index ceca40d2c..b15231188 100644 --- a/logger_test.go +++ b/logger_test.go @@ -6,7 +6,7 @@ import "testing" // logs of the given T passed from Test functions. // and records the text in the error log. // -// nolint + type testLogger struct { t *testing.T }