diff --git a/.golangci.yaml b/.golangci.yaml index c3fc3f8b..acd5a85d 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -289,6 +289,7 @@ linters: - bodyclose - depguard - errcheck + - errorlint - exportloopref - funlen - gci diff --git a/cmd/helm3.go b/cmd/helm3.go index 508a61c5..8eccf723 100644 --- a/cmd/helm3.go +++ b/cmd/helm3.go @@ -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) @@ -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 diff --git a/cmd/helpers.go b/cmd/helpers.go index 16e767e8..a0740efc 100644 --- a/cmd/helpers.go +++ b/cmd/helpers.go @@ -1,6 +1,7 @@ package cmd import ( + "errors" "fmt" "os" "os/exec" @@ -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 diff --git a/cmd/upgrade.go b/cmd/upgrade.go index 6874189e..4fe554f7 100644 --- a/cmd/upgrade.go +++ b/cmd/upgrade.go @@ -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 { diff --git a/main.go b/main.go index e3393999..8c321d1a 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "errors" "os" _ "k8s.io/client-go/plugin/pkg/client/auth/azure" @@ -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) } diff --git a/manifest/parse.go b/manifest/parse.go index 552a5ba3..0fec1506 100644 --- a/manifest/parse.go +++ b/manifest/parse.go @@ -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...)