fix(internal): errorlint linter

errorlint linter in internal/chart/v3/lint/rules

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
pull/31814/head
Matthieu MOREL 8 months ago
parent 1728ac6b83
commit a4af957efb

@ -16,7 +16,11 @@ limitations under the License.
package rules // import "helm.sh/helm/v4/internal/chart/v3/lint/rules"
import "testing"
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestValidateNoDeprecations(t *testing.T) {
deprecated := &k8sYamlStruct{
@ -27,7 +31,8 @@ func TestValidateNoDeprecations(t *testing.T) {
if err == nil {
t.Fatal("Expected deprecated extension to be flagged")
}
depErr := err.(deprecatedAPIError)
var depErr deprecatedAPIError
require.ErrorAs(t, err, &depErr)
if depErr.Message == "" {
t.Fatalf("Expected error message to be non-blank: %v", err)
}

@ -24,6 +24,8 @@ import (
"testing"
"time"
"github.com/stretchr/testify/require"
chart "helm.sh/helm/v4/internal/chart/v3"
"helm.sh/helm/v4/internal/chart/v3/lint/support"
chartutil "helm.sh/helm/v4/internal/chart/v3/util"
@ -220,7 +222,8 @@ func TestDeprecatedAPIFails(t *testing.T) {
t.Fatalf("Expected 1 lint error, got %d", l)
}
err := linter.Messages[0].Err.(deprecatedAPIError)
var err deprecatedAPIError
require.ErrorAs(t, linter.Messages[0].Err, &err)
if err.Deprecated != "apps/v1beta1 Deployment" {
t.Errorf("Surprised to learn that %q is deprecated", err.Deprecated)
}

@ -15,6 +15,7 @@ limitations under the License.
package util
import (
"errors"
"os"
"path/filepath"
"sort"
@ -251,8 +252,9 @@ func TestProcessDependencyImportValues(t *testing.T) {
if err == nil {
t.Error("expect nil value not found but found it")
}
switch xerr := err.(type) {
case common.ErrNoValue:
var xerr common.ErrNoValue
switch {
case errors.As(err, &xerr):
// We found what we expected
default:
t.Errorf("expected an ErrNoValue but got %q instead", xerr)

@ -18,6 +18,7 @@ package plugin
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"log/slog"
@ -156,7 +157,8 @@ func (r *SubprocessPluginRuntime) InvokeHook(event string) error {
slog.Debug("executing plugin hook command", slog.String("pluginName", r.metadata.Name), slog.String("command", cmd.String()))
if err := cmd.Run(); err != nil {
if eerr, ok := err.(*exec.ExitError); ok {
var eerr *exec.ExitError
if errors.As(err, &eerr) {
os.Stderr.Write(eerr.Stderr)
return fmt.Errorf("plugin %s hook for %q exited with error", event, r.metadata.Name)
}
@ -170,7 +172,8 @@ func (r *SubprocessPluginRuntime) InvokeHook(event string) error {
// then replace the other three with a call to this func
func executeCmd(prog *exec.Cmd, pluginName string) error {
if err := prog.Run(); err != nil {
if eerr, ok := err.(*exec.ExitError); ok {
var eerr *exec.ExitError
if errors.As(err, &eerr) {
slog.Debug(
"plugin execution failed",
slog.String("pluginName", pluginName),

@ -21,6 +21,7 @@ limitations under the License.
package sympath
import (
"errors"
"fmt"
"log/slog"
"os"
@ -40,7 +41,7 @@ func Walk(root string, walkFn filepath.WalkFunc) error {
} else {
err = symwalk(root, info, walkFn)
}
if err == filepath.SkipDir {
if errors.Is(err, filepath.SkipDir) {
return nil
}
return err
@ -75,7 +76,7 @@ func symwalk(path string, info os.FileInfo, walkFn filepath.WalkFunc) error {
if info, err = os.Lstat(resolved); err != nil {
return err
}
if err := symwalk(path, info, walkFn); err != nil && err != filepath.SkipDir {
if err := symwalk(path, info, walkFn); err != nil && !errors.Is(err, filepath.SkipDir) {
return err
}
return nil
@ -98,13 +99,13 @@ func symwalk(path string, info os.FileInfo, walkFn filepath.WalkFunc) error {
filename := filepath.Join(path, name)
fileInfo, err := os.Lstat(filename)
if err != nil {
if err := walkFn(filename, fileInfo, err); err != nil && err != filepath.SkipDir {
if err := walkFn(filename, fileInfo, err); err != nil && !errors.Is(err, filepath.SkipDir) {
return err
}
} else {
err = symwalk(filename, fileInfo, walkFn)
if err != nil {
if (!fileInfo.IsDir() && !IsSymlink(fileInfo)) || err != filepath.SkipDir {
if (!fileInfo.IsDir() && !IsSymlink(fileInfo)) || !errors.Is(err, filepath.SkipDir) {
return err
}
}

Loading…
Cancel
Save