From 360edd52b6c1e214f7eac9ec447ab612f4204437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20=C5=BBak?= Date: Mon, 6 Mar 2023 12:27:03 +0100 Subject: [PATCH] chore: Fix linter findings for errorlint (part8) (#12785) Co-authored-by: Pawel Zak --- .golangci.yml | 1 + config/plugin_id.go | 4 ++-- plugins/inputs/execd/shim/goshim.go | 9 +++++---- plugins/inputs/mysql/v2/convert.go | 4 +++- .../zipkin/cmd/thrift_serialize/thrift_serialize.go | 8 ++++---- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 045c43045..909e99374 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,6 +10,7 @@ linters: - dogsled - errcheck - errname + - errorlint - exportloopref - gocheckcompilerdirectives - goprintffuncname diff --git a/config/plugin_id.go b/config/plugin_id.go index 2f61cce5e..0b5b061d1 100644 --- a/config/plugin_id.go +++ b/config/plugin_id.go @@ -34,7 +34,7 @@ func processTable(parent string, table *ast.Table) ([]keyValuePair, error) { key := prefix + k childs, err := processTable(key, v) if err != nil { - return nil, fmt.Errorf("parsing table for %q failed: %v", key, err) + return nil, fmt.Errorf("parsing table for %q failed: %w", key, err) } options = append(options, childs...) case []*ast.Table: @@ -42,7 +42,7 @@ func processTable(parent string, table *ast.Table) ([]keyValuePair, error) { key := fmt.Sprintf("%s#%d.%s", prefix, i, k) childs, err := processTable(key, t) if err != nil { - return nil, fmt.Errorf("parsing table for %q #%d failed: %v", key, i, err) + return nil, fmt.Errorf("parsing table for %q #%d failed: %w", key, i, err) } options = append(options, childs...) } diff --git a/plugins/inputs/execd/shim/goshim.go b/plugins/inputs/execd/shim/goshim.go index 3f8284dbe..fb6278911 100644 --- a/plugins/inputs/execd/shim/goshim.go +++ b/plugins/inputs/execd/shim/goshim.go @@ -16,6 +16,7 @@ import ( "time" "github.com/BurntSushi/toml" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/agent" "github.com/influxdata/telegraf/plugins/inputs" @@ -69,7 +70,7 @@ func (s *Shim) AddInput(input telegraf.Input) error { if p, ok := input.(telegraf.Initializer); ok { err := p.Init() if err != nil { - return fmt.Errorf("failed to init input: %s", err) + return fmt.Errorf("failed to init input: %w", err) } } @@ -113,7 +114,7 @@ func (s *Shim) Run(pollInterval time.Duration) error { if serviceInput, ok := input.(telegraf.ServiceInput); ok { if err := serviceInput.Start(acc); err != nil { - return fmt.Errorf("failed to start input: %s", err) + return fmt.Errorf("failed to start input: %w", err) } } gatherPromptCh := make(chan empty, 1) @@ -150,11 +151,11 @@ loop: } b, err := serializer.Serialize(m) if err != nil { - return fmt.Errorf("failed to serialize metric: %s", err) + return fmt.Errorf("failed to serialize metric: %w", err) } // Write this to stdout if _, err := fmt.Fprint(s.stdout, string(b)); err != nil { - return fmt.Errorf("failed to write %q to stdout: %s", string(b), err) + return fmt.Errorf("failed to write %q to stdout: %w", string(b), err) } } } diff --git a/plugins/inputs/mysql/v2/convert.go b/plugins/inputs/mysql/v2/convert.go index 28e99b79e..6349b2749 100644 --- a/plugins/inputs/mysql/v2/convert.go +++ b/plugins/inputs/mysql/v2/convert.go @@ -3,6 +3,7 @@ package v2 import ( "bytes" "database/sql" + "errors" "fmt" "strconv" ) @@ -14,7 +15,8 @@ func ParseInt(value sql.RawBytes) (interface{}, error) { // Ignore ErrRange. When this error is set the returned value is "the // maximum magnitude integer of the appropriate bitSize and sign." - if err, ok := err.(*strconv.NumError); ok && err.Err == strconv.ErrRange { + var numErr *strconv.NumError + if errors.As(err, &numErr) && errors.Is(numErr, strconv.ErrRange) { return v, nil } diff --git a/plugins/inputs/zipkin/cmd/thrift_serialize/thrift_serialize.go b/plugins/inputs/zipkin/cmd/thrift_serialize/thrift_serialize.go index b8a0ff344..bc3207989 100644 --- a/plugins/inputs/zipkin/cmd/thrift_serialize/thrift_serialize.go +++ b/plugins/inputs/zipkin/cmd/thrift_serialize/thrift_serialize.go @@ -90,7 +90,7 @@ func jsonToZipkinThrift(jsonRaw []byte) ([]byte, error) { var spans []*zipkincore.Span err := json.Unmarshal(jsonRaw, &spans) if err != nil { - return nil, fmt.Errorf("error unmarshalling: %v", err) + return nil, fmt.Errorf("error unmarshalling: %w", err) } var zspans []*zipkincore.Span @@ -103,18 +103,18 @@ func jsonToZipkinThrift(jsonRaw []byte) ([]byte, error) { transport := thrift.NewTBinaryProtocolConf(buf, nil) if err = transport.WriteListBegin(context.Background(), thrift.STRUCT, len(spans)); err != nil { - return nil, fmt.Errorf("error in beginning thrift write: %v", err) + return nil, fmt.Errorf("error in beginning thrift write: %w", err) } for _, span := range zspans { err = span.Write(context.Background(), transport) if err != nil { - return nil, fmt.Errorf("error converting zipkin struct to thrift: %v", err) + return nil, fmt.Errorf("error converting zipkin struct to thrift: %w", err) } } if err = transport.WriteListEnd(context.Background()); err != nil { - return nil, fmt.Errorf("error finishing thrift write: %v", err) + return nil, fmt.Errorf("error finishing thrift write: %w", err) } return buf.Bytes(), nil