chore: Fix linter findings for errorlint (part8) (#12785)

Co-authored-by: Pawel Zak <Pawel Zak>
This commit is contained in:
Paweł Żak 2023-03-06 12:27:03 +01:00 committed by GitHub
parent 332997089b
commit 360edd52b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 11 deletions

View File

@ -10,6 +10,7 @@ linters:
- dogsled
- errcheck
- errname
- errorlint
- exportloopref
- gocheckcompilerdirectives
- goprintffuncname

View File

@ -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...)
}

View File

@ -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)
}
}
}

View File

@ -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
}

View File

@ -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