diff --git a/.golangci.yml b/.golangci.yml index 7eca135e5..92bb12828 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -20,6 +20,7 @@ linters: enable: - depguard - dupl + - errname - gomodguard - govet - ineffassign diff --git a/internal/chart/v3/lint/lint_test.go b/internal/chart/v3/lint/lint_test.go index 221de8572..4483d736b 100644 --- a/internal/chart/v3/lint/lint_test.go +++ b/internal/chart/v3/lint/lint_test.go @@ -224,7 +224,7 @@ func TestMalformedTemplate(t *testing.T) { var values map[string]any c := time.After(3 * time.Second) ch := make(chan int, 1) - var m []support.Message + var m []support.LintMessageError go func() { m = RunAll(malformedTemplate, values, namespace).Messages ch <- 1 diff --git a/internal/chart/v3/lint/support/message.go b/internal/chart/v3/lint/support/message.go index 5efbc7a61..702ec888d 100644 --- a/internal/chart/v3/lint/support/message.go +++ b/internal/chart/v3/lint/support/message.go @@ -35,27 +35,27 @@ var sev = []string{"UNKNOWN", "INFO", "WARNING", "ERROR"} // Linter encapsulates a linting run of a particular chart. type Linter struct { - Messages []Message + Messages []LintMessageError // The highest severity of all the failing lint rules HighestSeverity int ChartDir string } -// Message describes an error encountered while linting. -type Message struct { +// LintMessageError describes an error encountered while linting. +type LintMessageError struct { // Severity is one of the *Sev constants Severity int Path string Err error } -func (m Message) Error() string { +func (m LintMessageError) Error() string { return fmt.Sprintf("[%s] %s: %s", sev[m.Severity], m.Path, m.Err.Error()) } // NewMessage creates a new Message struct -func NewMessage(severity int, path string, err error) Message { - return Message{Severity: severity, Path: path, Err: err} +func NewMessage(severity int, path string, err error) LintMessageError { + return LintMessageError{Severity: severity, Path: path, Err: err} } // RunLinterRule returns true if the validation passed diff --git a/internal/chart/v3/lint/support/message_test.go b/internal/chart/v3/lint/support/message_test.go index ce5b5e42e..3e8ef0118 100644 --- a/internal/chart/v3/lint/support/message_test.go +++ b/internal/chart/v3/lint/support/message_test.go @@ -62,17 +62,17 @@ func TestRunLinterRule(t *testing.T) { } func TestMessage(t *testing.T) { - m := Message{ErrorSev, "Chart.yaml", errors.New("Foo")} + m := LintMessageError{ErrorSev, "Chart.yaml", errors.New("Foo")} if m.Error() != "[ERROR] Chart.yaml: Foo" { t.Errorf("Unexpected output: %s", m.Error()) } - m = Message{WarningSev, "templates/", errors.New("Bar")} + m = LintMessageError{WarningSev, "templates/", errors.New("Bar")} if m.Error() != "[WARNING] templates/: Bar" { t.Errorf("Unexpected output: %s", m.Error()) } - m = Message{InfoSev, "templates/rc.yaml", errors.New("FooBar")} + m = LintMessageError{InfoSev, "templates/rc.yaml", errors.New("FooBar")} if m.Error() != "[INFO] templates/rc.yaml: FooBar" { t.Errorf("Unexpected output: %s", m.Error()) } diff --git a/internal/chart/v3/util/dependencies.go b/internal/chart/v3/util/dependencies.go index 4ef9e6961..7a1722fe7 100644 --- a/internal/chart/v3/util/dependencies.go +++ b/internal/chart/v3/util/dependencies.go @@ -51,7 +51,7 @@ func processDependencyConditions(reqs []*chart.Dependency, cvals common.Values, break } slog.Warn("returned non-bool value", "path", c, "chart", r.Name) - } else if _, ok := err.(common.ErrNoValue); !ok { + } else if _, ok := err.(common.NoValueError); !ok { // this is a real error slog.Warn("the method PathValue returned error", slog.Any("error", err)) } diff --git a/internal/chart/v3/util/dependencies_test.go b/internal/chart/v3/util/dependencies_test.go index 3c5bb96f7..13e16cc15 100644 --- a/internal/chart/v3/util/dependencies_test.go +++ b/internal/chart/v3/util/dependencies_test.go @@ -252,10 +252,10 @@ func TestProcessDependencyImportValues(t *testing.T) { t.Error("expect nil value not found but found it") } switch xerr := err.(type) { - case common.ErrNoValue: + case common.NoValueError: // We found what we expected default: - t.Errorf("expected an ErrNoValue but got %q instead", xerr) + t.Errorf("expected a NoValueError but got %q instead", xerr) } c = loadChart(t, "testdata/subpop") diff --git a/internal/chart/v3/util/save.go b/internal/chart/v3/util/save.go index f886c6175..460d5220f 100644 --- a/internal/chart/v3/util/save.go +++ b/internal/chart/v3/util/save.go @@ -250,7 +250,7 @@ func validateName(name string) error { nname := filepath.Base(name) if nname != name { - return common.ErrInvalidChartName{Name: name} + return common.InvalidChartNameError{Name: name} } return nil diff --git a/pkg/action/lint.go b/pkg/action/lint.go index 208fd4637..3057ea45c 100644 --- a/pkg/action/lint.go +++ b/pkg/action/lint.go @@ -43,7 +43,7 @@ type Lint struct { // LintResult is the result of Lint type LintResult struct { TotalChartsLinted int - Messages []support.Message + Messages []support.LintMessageError Errors []error } diff --git a/pkg/action/uninstall.go b/pkg/action/uninstall.go index efbc72fef..8564100d1 100644 --- a/pkg/action/uninstall.go +++ b/pkg/action/uninstall.go @@ -222,19 +222,19 @@ func (u *Uninstall) purgeReleases(rels ...*release.Release) error { return nil } -type joinedErrors struct { +type joinedListError struct { errs []error sep string } func joinErrors(errs []error, sep string) error { - return &joinedErrors{ + return &joinedListError{ errs: errs, sep: sep, } } -func (e *joinedErrors) Error() string { +func (e *joinedListError) Error() string { errs := make([]string, 0, len(e.errs)) for _, err := range e.errs { errs = append(errs, err.Error()) @@ -242,7 +242,7 @@ func (e *joinedErrors) Error() string { return strings.Join(errs, e.sep) } -func (e *joinedErrors) Unwrap() []error { +func (e *joinedListError) Unwrap() []error { return e.errs } diff --git a/pkg/chart/common/errors.go b/pkg/chart/common/errors.go index b0a2d650e..b6c99e7a5 100644 --- a/pkg/chart/common/errors.go +++ b/pkg/chart/common/errors.go @@ -20,24 +20,24 @@ import ( "fmt" ) -// ErrNoTable indicates that a chart does not have a matching table. -type ErrNoTable struct { +// NoTableError indicates that a chart does not have a matching table. +type NoTableError struct { Key string } -func (e ErrNoTable) Error() string { return fmt.Sprintf("%q is not a table", e.Key) } +func (e NoTableError) Error() string { return fmt.Sprintf("%q is not a table", e.Key) } -// ErrNoValue indicates that Values does not contain a key with a value -type ErrNoValue struct { +// NoValueError indicates that Values does not contain a key with a value +type NoValueError struct { Key string } -func (e ErrNoValue) Error() string { return fmt.Sprintf("%q is not a value", e.Key) } +func (e NoValueError) Error() string { return fmt.Sprintf("%q is not a value", e.Key) } -type ErrInvalidChartName struct { +type InvalidChartNameError struct { Name string } -func (e ErrInvalidChartName) Error() string { +func (e InvalidChartNameError) Error() string { return fmt.Sprintf("%q is not a valid chart name", e.Name) } diff --git a/pkg/chart/common/errors_test.go b/pkg/chart/common/errors_test.go index 06b3b054c..e784acfed 100644 --- a/pkg/chart/common/errors_test.go +++ b/pkg/chart/common/errors_test.go @@ -23,7 +23,7 @@ import ( func TestErrorNoTableDoesNotPanic(t *testing.T) { x := "empty" - y := ErrNoTable{x} + y := NoTableError{x} t.Logf("error is: %s", y) } @@ -31,7 +31,7 @@ func TestErrorNoTableDoesNotPanic(t *testing.T) { func TestErrorNoValueDoesNotPanic(t *testing.T) { x := "empty" - y := ErrNoValue{x} + y := NoValueError{x} t.Logf("error is: %s", y) } diff --git a/pkg/chart/common/values.go b/pkg/chart/common/values.go index 94958a779..64e62ec42 100644 --- a/pkg/chart/common/values.go +++ b/pkg/chart/common/values.go @@ -48,7 +48,7 @@ func (v Values) YAML() (string, error) { // The above will be evaluated as "The table bar inside the table // foo". // -// An ErrNoTable is returned if the table does not exist. +// An NoTableError is returned if the table does not exist. func (v Values) Table(name string) (Values, error) { table := v var err error @@ -84,7 +84,7 @@ func (v Values) Encode(w io.Writer) error { func tableLookup(v Values, simple string) (Values, error) { v2, ok := v[simple] if !ok { - return v, ErrNoTable{simple} + return v, NoTableError{simple} } if vv, ok := v2.(map[string]interface{}); ok { return vv, nil @@ -97,7 +97,7 @@ func tableLookup(v Values, simple string) (Values, error) { return vv, nil } - return Values{}, ErrNoTable{simple} + return Values{}, NoTableError{simple} } // ReadValues will parse YAML byte data into a Values. @@ -154,20 +154,20 @@ func (v Values) pathValue(path []string) (interface{}, error) { if _, ok := v[path[0]]; ok && !istable(v[path[0]]) { return v[path[0]], nil } - return nil, ErrNoValue{path[0]} + return nil, NoValueError{path[0]} } key, path := path[len(path)-1], path[:len(path)-1] // get our table for table path t, err := v.Table(joinPath(path...)) if err != nil { - return nil, ErrNoValue{key} + return nil, NoValueError{key} } // check table for key and ensure value is not a table if k, ok := t[key]; ok && !istable(k) { return k, nil } - return nil, ErrNoValue{key} + return nil, NoValueError{key} } func parsePath(key string) []string { return strings.Split(key, ".") } diff --git a/pkg/chart/v2/lint/lint_test.go b/pkg/chart/v2/lint/lint_test.go index 80dcef932..d17c5171f 100644 --- a/pkg/chart/v2/lint/lint_test.go +++ b/pkg/chart/v2/lint/lint_test.go @@ -228,7 +228,7 @@ func TestMalformedTemplate(t *testing.T) { var values map[string]any c := time.After(3 * time.Second) ch := make(chan int, 1) - var m []support.Message + var m []support.LintMessageError go func() { m = RunAll(malformedTemplate, values, namespace).Messages ch <- 1 diff --git a/pkg/chart/v2/lint/support/message.go b/pkg/chart/v2/lint/support/message.go index 5efbc7a61..f01d7fc76 100644 --- a/pkg/chart/v2/lint/support/message.go +++ b/pkg/chart/v2/lint/support/message.go @@ -35,27 +35,27 @@ var sev = []string{"UNKNOWN", "INFO", "WARNING", "ERROR"} // Linter encapsulates a linting run of a particular chart. type Linter struct { - Messages []Message + Messages []LintMessageError // The highest severity of all the failing lint rules HighestSeverity int ChartDir string } // Message describes an error encountered while linting. -type Message struct { +type LintMessageError struct { // Severity is one of the *Sev constants Severity int Path string Err error } -func (m Message) Error() string { +func (m LintMessageError) Error() string { return fmt.Sprintf("[%s] %s: %s", sev[m.Severity], m.Path, m.Err.Error()) } // NewMessage creates a new Message struct -func NewMessage(severity int, path string, err error) Message { - return Message{Severity: severity, Path: path, Err: err} +func NewMessage(severity int, path string, err error) LintMessageError { + return LintMessageError{Severity: severity, Path: path, Err: err} } // RunLinterRule returns true if the validation passed diff --git a/pkg/chart/v2/lint/support/message_test.go b/pkg/chart/v2/lint/support/message_test.go index ce5b5e42e..3e8ef0118 100644 --- a/pkg/chart/v2/lint/support/message_test.go +++ b/pkg/chart/v2/lint/support/message_test.go @@ -62,17 +62,17 @@ func TestRunLinterRule(t *testing.T) { } func TestMessage(t *testing.T) { - m := Message{ErrorSev, "Chart.yaml", errors.New("Foo")} + m := LintMessageError{ErrorSev, "Chart.yaml", errors.New("Foo")} if m.Error() != "[ERROR] Chart.yaml: Foo" { t.Errorf("Unexpected output: %s", m.Error()) } - m = Message{WarningSev, "templates/", errors.New("Bar")} + m = LintMessageError{WarningSev, "templates/", errors.New("Bar")} if m.Error() != "[WARNING] templates/: Bar" { t.Errorf("Unexpected output: %s", m.Error()) } - m = Message{InfoSev, "templates/rc.yaml", errors.New("FooBar")} + m = LintMessageError{InfoSev, "templates/rc.yaml", errors.New("FooBar")} if m.Error() != "[INFO] templates/rc.yaml: FooBar" { t.Errorf("Unexpected output: %s", m.Error()) } diff --git a/pkg/chart/v2/util/dependencies.go b/pkg/chart/v2/util/dependencies.go index c7bb6621e..152c0935c 100644 --- a/pkg/chart/v2/util/dependencies.go +++ b/pkg/chart/v2/util/dependencies.go @@ -51,7 +51,7 @@ func processDependencyConditions(reqs []*chart.Dependency, cvals common.Values, break } slog.Warn("returned non-bool value", "path", c, "chart", r.Name) - } else if _, ok := err.(common.ErrNoValue); !ok { + } else if _, ok := err.(common.NoValueError); !ok { // this is a real error slog.Warn("the method PathValue returned error", slog.Any("error", err)) } diff --git a/pkg/chart/v2/util/dependencies_test.go b/pkg/chart/v2/util/dependencies_test.go index c817b0b89..7b806f373 100644 --- a/pkg/chart/v2/util/dependencies_test.go +++ b/pkg/chart/v2/util/dependencies_test.go @@ -252,10 +252,10 @@ func TestProcessDependencyImportValues(t *testing.T) { t.Error("expect nil value not found but found it") } switch xerr := err.(type) { - case common.ErrNoValue: + case common.NoValueError: // We found what we expected default: - t.Errorf("expected an ErrNoValue but got %q instead", xerr) + t.Errorf("expected a NoValueError but got %q instead", xerr) } c = loadChart(t, "testdata/subpop") diff --git a/pkg/chart/v2/util/save.go b/pkg/chart/v2/util/save.go index e66d86991..132437d24 100644 --- a/pkg/chart/v2/util/save.go +++ b/pkg/chart/v2/util/save.go @@ -262,7 +262,7 @@ func validateName(name string) error { nname := filepath.Base(name) if nname != name { - return common.ErrInvalidChartName{Name: name} + return common.InvalidChartNameError{Name: name} } return nil diff --git a/pkg/cmd/dependency_build.go b/pkg/cmd/dependency_build.go index 7e5c731b7..13a309e0c 100644 --- a/pkg/cmd/dependency_build.go +++ b/pkg/cmd/dependency_build.go @@ -76,7 +76,7 @@ func newDependencyBuildCmd(out io.Writer) *cobra.Command { man.Verify = downloader.VerifyIfPossible } err = man.Build() - if e, ok := err.(downloader.ErrRepoNotFound); ok { + if e, ok := err.(downloader.RepoNotFoundError); ok { return fmt.Errorf("%s. Please add the missing repos via 'helm repo add'", e.Error()) } return err diff --git a/pkg/downloader/manager.go b/pkg/downloader/manager.go index 6043fbaaa..f95071855 100644 --- a/pkg/downloader/manager.go +++ b/pkg/downloader/manager.go @@ -45,14 +45,14 @@ import ( "helm.sh/helm/v4/pkg/repo/v1" ) -// ErrRepoNotFound indicates that chart repositories can't be found in local repo cache. +// RepoNotFoundError indicates that chart repositories can't be found in local repo cache. // The value of Repos is missing repos. -type ErrRepoNotFound struct { +type RepoNotFoundError struct { Repos []string } // Error implements the error interface. -func (e ErrRepoNotFound) Error() string { +func (e RepoNotFoundError) Error() string { return fmt.Sprintf("no repository definition for %s", strings.Join(e.Repos, ", ")) } @@ -491,7 +491,7 @@ Loop: missing = append(missing, dd.Repository) } if len(missing) > 0 { - return ErrRepoNotFound{missing} + return RepoNotFoundError{missing} } return nil } diff --git a/pkg/downloader/manager_test.go b/pkg/downloader/manager_test.go index 9e27f183f..85619e196 100644 --- a/pkg/downloader/manager_test.go +++ b/pkg/downloader/manager_test.go @@ -569,7 +569,7 @@ func TestErrRepoNotFound_Error(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - e := ErrRepoNotFound{ + e := RepoNotFoundError{ Repos: tt.fields.Repos, } if got := e.Error(); got != tt.want { diff --git a/pkg/kube/client.go b/pkg/kube/client.go index 6e09fceac..1ecdd0d5f 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -1247,19 +1247,19 @@ func scrubValidationError(err error) error { return err } -type joinedErrors struct { +type joinedListError struct { errs []error sep string } func joinErrors(errs []error, sep string) error { - return &joinedErrors{ + return &joinedListError{ errs: errs, sep: sep, } } -func (e *joinedErrors) Error() string { +func (e *joinedListError) Error() string { errs := make([]string, 0, len(e.errs)) for _, err := range e.errs { errs = append(errs, err.Error()) @@ -1267,6 +1267,6 @@ func (e *joinedErrors) Error() string { return strings.Join(errs, e.sep) } -func (e *joinedErrors) Unwrap() []error { +func (e *joinedListError) Unwrap() []error { return e.errs }