Skip to content

enable errorlint linter #594

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

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ linters:
- bodyclose
- depguard
- errcheck
- errorlint
- exportloopref
- funlen
- gci
Expand Down
4 changes: 2 additions & 2 deletions cmd/helm3.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func getHelmVersion() (*semver.Version, error) {
debugPrint("Executing %s", strings.Join(cmd.Args, " "))
output, err := cmd.CombinedOutput()
if err != nil {
return nil, fmt.Errorf("Failed to run `%s version`: %v", os.Getenv("HELM_BIN"), err)
return nil, fmt.Errorf("Failed to run `%s version`: %w", os.Getenv("HELM_BIN"), err)
}
versionOutput := string(output)

Expand All @@ -35,7 +35,7 @@ func getHelmVersion() (*semver.Version, error) {
}
helmVersion, err := semver.NewVersion(matches[1])
if err != nil {
return nil, fmt.Errorf("Failed to parse version %#v: %v", matches[1], err)
return nil, fmt.Errorf("Failed to parse version %#v: %w", matches[1], err)
}

return helmVersion, nil
Expand Down
4 changes: 3 additions & 1 deletion cmd/helpers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"errors"
"fmt"
"os"
"os/exec"
Expand Down Expand Up @@ -32,7 +33,8 @@ func debugPrint(format string, a ...interface{}) {
func outputWithRichError(cmd *exec.Cmd) ([]byte, error) {
debugPrint("Executing %s", strings.Join(cmd.Args, " "))
output, err := cmd.Output()
if exitError, ok := err.(*exec.ExitError); ok {
var exitError *exec.ExitError
if errors.As(err, &exitError) {
return output, fmt.Errorf("%s: %s", exitError.Error(), string(exitError.Stderr))
}
return output, err
Expand Down
4 changes: 2 additions & 2 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,12 @@ func (d *diffCmd) runHelm3() error {
}
}
if err != nil {
return fmt.Errorf("Failed to get release %s in namespace %s: %s", d.release, d.namespace, err)
return fmt.Errorf("Failed to get release %s in namespace %s: %w", d.release, d.namespace, err)
}

installManifest, err := d.template(!newInstall)
if err != nil {
return fmt.Errorf("Failed to render chart: %s", err)
return fmt.Errorf("Failed to render chart: %w", err)
}

if d.threeWayMerge {
Expand Down
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"os"

_ "k8s.io/client-go/plugin/pkg/client/auth/azure"
Expand All @@ -13,9 +14,10 @@ import (

func main() {
if err := cmd.New().Execute(); err != nil {
switch e := err.(type) {
case cmd.Error:
os.Exit(e.Code)
var cmdErr cmd.Error
switch {
case errors.As(err, &cmdErr):
os.Exit(cmdErr.Code)
default:
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion manifest/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func parseContent(content string, defaultNamespace string, normalizeManifests bo

subs, err := parseContent(string(subcontent), defaultNamespace, normalizeManifests, excludedHooks...)
if err != nil {
return nil, fmt.Errorf("Parsing YAML list item: %v", err)
return nil, fmt.Errorf("Parsing YAML list item: %w", err)
}

result = append(result, subs...)
Expand Down