chore: Fix linter findings for errorlint (part8) (#12785)
Co-authored-by: Pawel Zak <Pawel Zak>
This commit is contained in:
parent
332997089b
commit
360edd52b6
|
|
@ -10,6 +10,7 @@ linters:
|
||||||
- dogsled
|
- dogsled
|
||||||
- errcheck
|
- errcheck
|
||||||
- errname
|
- errname
|
||||||
|
- errorlint
|
||||||
- exportloopref
|
- exportloopref
|
||||||
- gocheckcompilerdirectives
|
- gocheckcompilerdirectives
|
||||||
- goprintffuncname
|
- goprintffuncname
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ func processTable(parent string, table *ast.Table) ([]keyValuePair, error) {
|
||||||
key := prefix + k
|
key := prefix + k
|
||||||
childs, err := processTable(key, v)
|
childs, err := processTable(key, v)
|
||||||
if err != nil {
|
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...)
|
options = append(options, childs...)
|
||||||
case []*ast.Table:
|
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)
|
key := fmt.Sprintf("%s#%d.%s", prefix, i, k)
|
||||||
childs, err := processTable(key, t)
|
childs, err := processTable(key, t)
|
||||||
if err != nil {
|
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...)
|
options = append(options, childs...)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/agent"
|
"github.com/influxdata/telegraf/agent"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"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 {
|
if p, ok := input.(telegraf.Initializer); ok {
|
||||||
err := p.Init()
|
err := p.Init()
|
||||||
if err != nil {
|
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 serviceInput, ok := input.(telegraf.ServiceInput); ok {
|
||||||
if err := serviceInput.Start(acc); err != nil {
|
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)
|
gatherPromptCh := make(chan empty, 1)
|
||||||
|
|
@ -150,11 +151,11 @@ loop:
|
||||||
}
|
}
|
||||||
b, err := serializer.Serialize(m)
|
b, err := serializer.Serialize(m)
|
||||||
if err != nil {
|
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
|
// Write this to stdout
|
||||||
if _, err := fmt.Fprint(s.stdout, string(b)); err != nil {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package v2
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
@ -14,7 +15,8 @@ func ParseInt(value sql.RawBytes) (interface{}, error) {
|
||||||
|
|
||||||
// Ignore ErrRange. When this error is set the returned value is "the
|
// Ignore ErrRange. When this error is set the returned value is "the
|
||||||
// maximum magnitude integer of the appropriate bitSize and sign."
|
// 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
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ func jsonToZipkinThrift(jsonRaw []byte) ([]byte, error) {
|
||||||
var spans []*zipkincore.Span
|
var spans []*zipkincore.Span
|
||||||
err := json.Unmarshal(jsonRaw, &spans)
|
err := json.Unmarshal(jsonRaw, &spans)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error unmarshalling: %v", err)
|
return nil, fmt.Errorf("error unmarshalling: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var zspans []*zipkincore.Span
|
var zspans []*zipkincore.Span
|
||||||
|
|
@ -103,18 +103,18 @@ func jsonToZipkinThrift(jsonRaw []byte) ([]byte, error) {
|
||||||
transport := thrift.NewTBinaryProtocolConf(buf, nil)
|
transport := thrift.NewTBinaryProtocolConf(buf, nil)
|
||||||
|
|
||||||
if err = transport.WriteListBegin(context.Background(), thrift.STRUCT, len(spans)); err != 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 {
|
for _, span := range zspans {
|
||||||
err = span.Write(context.Background(), transport)
|
err = span.Write(context.Background(), transport)
|
||||||
if err != nil {
|
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 {
|
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
|
return buf.Bytes(), nil
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue