Skip to content

Commit

Permalink
chore: Fix linter findings for errorlint (part8) (influxdata#12785)
Browse files Browse the repository at this point in the history
Co-authored-by: Pawel Zak <Pawel Zak>
  • Loading branch information
zak-pawel authored Mar 6, 2023
1 parent 3329970 commit 360edd5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ linters:
- dogsled
- errcheck
- errname
- errorlint
- exportloopref
- gocheckcompilerdirectives
- goprintffuncname
Expand Down
4 changes: 2 additions & 2 deletions config/plugin_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ 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:
for i, t := range v {
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...)
}
Expand Down
9 changes: 5 additions & 4 deletions plugins/inputs/execd/shim/goshim.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion plugins/inputs/mysql/v2/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v2
import (
"bytes"
"database/sql"
"errors"
"fmt"
"strconv"
)
Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 360edd5

Please sign in to comment.