-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Fix linter findings for errorlint (part2) #12702
Conversation
Download PR build artifacts for linux_amd64.tar.gz, darwin_amd64.tar.gz, and windows_amd64.zip. 📦 Click here to get additional PR build artifactsArtifact URLs |
@@ -393,17 +393,17 @@ outer: | |||
case "int": | |||
val, err = strconv.ParseInt(value, 10, 64) | |||
if err != nil { | |||
return nil, fmt.Errorf("column type: parse int error %s", err) | |||
return nil, fmt.Errorf("column type: parse int error %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, fmt.Errorf("column type: parse int error %w", err) | |
return nil, fmt.Errorf("column type: parse int error: %w", err) |
} | ||
case "float": | ||
val, err = strconv.ParseFloat(value, 64) | ||
if err != nil { | ||
return nil, fmt.Errorf("column type: parse float error %s", err) | ||
return nil, fmt.Errorf("column type: parse float error %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, fmt.Errorf("column type: parse float error %w", err) | |
return nil, fmt.Errorf("column type: parse float error: %w", err) |
} | ||
case "bool": | ||
val, err = strconv.ParseBool(value) | ||
if err != nil { | ||
return nil, fmt.Errorf("column type: parse bool error %s", err) | ||
return nil, fmt.Errorf("column type: parse bool error %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, fmt.Errorf("column type: parse bool error %w", err) | |
return nil, fmt.Errorf("column type: parse bool error: %w", err) |
@@ -108,7 +108,7 @@ func (p *Parser) ParseLine(line string) (telegraf.Metric, error) { | |||
// Parse value. | |||
v, err := strconv.ParseFloat(fields[1], 64) | |||
if err != nil { | |||
return nil, fmt.Errorf(`field "%s" value: %s`, fields[0], err) | |||
return nil, fmt.Errorf(`field "%s" value: %w`, fields[0], err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, fmt.Errorf(`field "%s" value: %w`, fields[0], err) | |
return nil, fmt.Errorf("field %q value: %w", fields[0], err) |
@@ -125,7 +125,7 @@ func (p *Parser) ParseLine(line string) (telegraf.Metric, error) { | |||
// Parse timestamp. | |||
unixTime, err := strconv.ParseFloat(fields[2], 64) | |||
if err != nil { | |||
return nil, fmt.Errorf(`field "%s" time: %s`, fields[0], err) | |||
return nil, fmt.Errorf(`field "%s" time: %w`, fields[0], err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, fmt.Errorf(`field "%s" time: %w`, fields[0], err) | |
return nil, fmt.Errorf("field %q time: %w", fields[0], err) |
} | ||
return r, nil | ||
case "int": | ||
r, err := strconv.ParseInt(inputType, 10, 64) | ||
if err != nil { | ||
return nil, fmt.Errorf("Unable to convert field '%s' to type int: %v", name, err) | ||
return nil, fmt.Errorf("unable to convert field '%s' to type int: %w", name, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, fmt.Errorf("unable to convert field '%s' to type int: %w", name, err) | |
return nil, fmt.Errorf("unable to convert field %q to type int: %w", name, err) |
@@ -586,25 +586,25 @@ func (p *Parser) convertType(input gjson.Result, desiredType string, name string | |||
case "uint": | |||
r, err := strconv.ParseUint(inputType, 10, 64) | |||
if err != nil { | |||
return nil, fmt.Errorf("Unable to convert field '%s' to type uint: %v", name, err) | |||
return nil, fmt.Errorf("unable to convert field '%s' to type uint: %w", name, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, fmt.Errorf("unable to convert field '%s' to type uint: %w", name, err) | |
return nil, fmt.Errorf("unable to convert field %q to type uint: %w", name, err) |
Honestly, I think just %s
would be sufficient as well for these..
@@ -91,7 +91,7 @@ func (t *TopK) generateGroupByKey(m telegraf.Metric) (string, error) { | |||
var err error | |||
t.tagsGlobs, err = filter.Compile(t.GroupBy) | |||
if err != nil { | |||
return "", fmt.Errorf("could not compile pattern: %v %v", t.GroupBy, err) | |||
return "", fmt.Errorf("could not compile pattern: %v %w", t.GroupBy, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return "", fmt.Errorf("could not compile pattern: %v %w", t.GroupBy, err) | |
return "", fmt.Errorf("could not compile pattern %q: %w", t.GroupBy, err) |
@@ -128,7 +128,7 @@ func (p *Parser) parseTime(buf []byte) (time.Time, error) { | |||
} | |||
t, err := time.Parse(timeFormat, timeString) | |||
if err != nil { | |||
return time.Time{}, fmt.Errorf("time %s cannot be parsed with format %s, %s", timeString, timeFormat, err) | |||
return time.Time{}, fmt.Errorf("time %s cannot be parsed with format %s, %w", timeString, timeFormat, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #12701 (review)
@@ -154,7 +154,7 @@ func (p *Parser) unmarshalMetrics(buf []byte) (map[string]interface{}, error) { | |||
var jsonOut map[string]interface{} | |||
err := json.Unmarshal(registryBytes, &jsonOut) | |||
if err != nil { | |||
err = fmt.Errorf("unable to parse dropwizard metric registry from JSON document, %s", err) | |||
err = fmt.Errorf("unable to parse dropwizard metric registry from JSON document, %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #12701 (review)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I agree with @Hipska's comments to unify error messaging format and use %q
, I also think this is beyond the present PR. Therefor, I do approve and merge the PR. A checker for %q
would be awesome for the next linter round. ;-)
if err == ErrEOF { | ||
if errors.Is(err, ErrEOF) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could make use of require.ErrorIs
here (see https://pkg.go.dev/github.com/stretchr/testify/require#ErrorIs), but I don't want to hold up this PR for that small improvement.
There were also other instances where a I will put up a PR changing all to |
Co-authored-by: Pawel Zak <Pawel Zak> (cherry picked from commit 4201f24)
Address findings for errorlint - finds code that can cause problems with the error wrapping scheme introduced in Go 1.13.
It is only part of the bigger job.
After all findings in whole project are handled, we can enable
errorlint
linter to guard this.Following findings in
plugins/aggregators
,plugins/common
,plugins/parsers
,plugins/processors
,plugins/secretstores
andplugins/serializers
packages were fixed: