fix(pkg): errorlint linter

errorlint linter in pkg/cmd

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
pull/31811/head
Matthieu MOREL 7 months ago
parent 9b22aa4e05
commit 259f76a849

@ -488,7 +488,7 @@ func (i *Install) performInstall(rel *release.Release, toBeAdopted kube.Resource
// pre-install hooks // pre-install hooks
if !i.DisableHooks { if !i.DisableHooks {
if err := i.cfg.execHook(rel, release.HookPreInstall, i.WaitStrategy, i.WaitOptions, i.Timeout, i.ServerSideApply); err != nil { if err := i.cfg.execHook(rel, release.HookPreInstall, i.WaitStrategy, i.WaitOptions, i.Timeout, i.ServerSideApply); err != nil {
return rel, fmt.Errorf("failed pre-install: %s", err) return rel, fmt.Errorf("failed pre-install: %w", err)
} }
} }
@ -534,7 +534,7 @@ func (i *Install) performInstall(rel *release.Release, toBeAdopted kube.Resource
if !i.DisableHooks { if !i.DisableHooks {
if err := i.cfg.execHook(rel, release.HookPostInstall, i.WaitStrategy, i.WaitOptions, i.Timeout, i.ServerSideApply); err != nil { if err := i.cfg.execHook(rel, release.HookPostInstall, i.WaitStrategy, i.WaitOptions, i.Timeout, i.ServerSideApply); err != nil {
return rel, fmt.Errorf("failed post-install: %s", err) return rel, fmt.Errorf("failed post-install: %w", err)
} }
} }

@ -16,6 +16,7 @@ limitations under the License.
package util package util
import ( import (
"errors"
"fmt" "fmt"
"log/slog" "log/slog"
"strings" "strings"
@ -44,6 +45,7 @@ func processDependencyConditions(reqs []*chart.Dependency, cvals common.Values,
if len(c) > 0 { if len(c) > 0 {
// retrieve value // retrieve value
vv, err := cvals.PathValue(cpath + c) vv, err := cvals.PathValue(cpath + c)
var errNoValue common.ErrNoValue
if err == nil { if err == nil {
// if not bool, warn // if not bool, warn
if bv, ok := vv.(bool); ok { if bv, ok := vv.(bool); ok {
@ -51,7 +53,7 @@ func processDependencyConditions(reqs []*chart.Dependency, cvals common.Values,
break break
} }
slog.Warn("returned non-bool value", "path", c, "chart", r.Name) slog.Warn("returned non-bool value", "path", c, "chart", r.Name)
} else if _, ok := err.(common.ErrNoValue); !ok { } else if !errors.As(err, &errNoValue) {
// this is a real error // this is a real error
slog.Warn("the method PathValue returned error", slog.Any("error", err)) slog.Warn("the method PathValue returned error", slog.Any("error", err))
} }

@ -16,6 +16,7 @@ limitations under the License.
package cmd package cmd
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -76,7 +77,8 @@ func newDependencyBuildCmd(out io.Writer) *cobra.Command {
man.Verify = downloader.VerifyIfPossible man.Verify = downloader.VerifyIfPossible
} }
err = man.Build() err = man.Build()
if e, ok := err.(downloader.ErrRepoNotFound); ok { var e downloader.ErrRepoNotFound
if errors.As(err, &e) {
return fmt.Errorf("%s. Please add the missing repos via 'helm repo add'", e.Error()) return fmt.Errorf("%s. Please add the missing repos via 'helm repo add'", e.Error())
} }
return err return err

@ -18,6 +18,7 @@ package cmd
import ( import (
"bytes" "bytes"
"context" "context"
"errors"
"fmt" "fmt"
"io" "io"
"log/slog" "log/slog"
@ -120,7 +121,8 @@ func loadCLIPlugins(baseCmd *cobra.Command, out io.Writer) {
Stderr: os.Stderr, Stderr: os.Stderr,
} }
_, err = plug.Invoke(context.Background(), input) _, err = plug.Invoke(context.Background(), input)
if execErr, ok := err.(*plugin.InvokeExecError); ok { execErr := &plugin.InvokeExecError{}
if errors.As(err, &execErr) {
return CommandError{ return CommandError{
error: execErr.Err, error: execErr.Err,
ExitCode: execErr.ExitCode, ExitCode: execErr.ExitCode,

@ -180,7 +180,7 @@ func TestConfigMapQuery(t *testing.T) {
} }
_, err = cfgmaps.Query(map[string]string{"name": "notExist"}) _, err = cfgmaps.Query(map[string]string{"name": "notExist"})
if err != ErrReleaseNotFound { if !errors.Is(err, ErrReleaseNotFound) {
t.Errorf("Expected {%v}, got {%v}", ErrReleaseNotFound, err) t.Errorf("Expected {%v}, got {%v}", ErrReleaseNotFound, err)
} }
} }
@ -252,7 +252,7 @@ func TestConfigMapDelete(t *testing.T) {
// perform the delete on a non-existent release // perform the delete on a non-existent release
_, err := cfgmaps.Delete("nonexistent") _, err := cfgmaps.Delete("nonexistent")
if err != ErrReleaseNotFound { if !errors.Is(err, ErrReleaseNotFound) {
t.Fatalf("Expected ErrReleaseNotFound: got {%v}", err) t.Fatalf("Expected ErrReleaseNotFound: got {%v}", err)
} }

Loading…
Cancel
Save