Enable the errname linter.

Signed-off-by: Mads Jensen <atombrella@users.noreply.github.com>
pull/31647/head
Mads Jensen 2 weeks ago
parent 5d2ab10caa
commit 4ec0b32ac7

@ -20,6 +20,7 @@ linters:
enable:
- depguard
- dupl
- errname
- gomodguard
- govet
- ineffassign

@ -234,7 +234,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.MessageError
go func() {
m = RunAll(malformedTemplate, values, namespace).Messages
ch <- 1

@ -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 []MessageError
// The highest severity of all the failing lint rules
HighestSeverity int
ChartDir string
}
// Message describes an error encountered while linting.
type Message struct {
type MessageError struct {
// Severity is one of the *Sev constants
Severity int
Path string
Err error
}
func (m Message) Error() string {
func (m MessageError) 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) MessageError {
return MessageError{Severity: severity, Path: path, Err: err}
}
// RunLinterRule returns true if the validation passed

@ -62,17 +62,17 @@ func TestRunLinterRule(t *testing.T) {
}
func TestMessage(t *testing.T) {
m := Message{ErrorSev, "Chart.yaml", errors.New("Foo")}
m := MessageError{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 = MessageError{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 = MessageError{InfoSev, "templates/rc.yaml", errors.New("FooBar")}
if m.Error() != "[INFO] templates/rc.yaml: FooBar" {
t.Errorf("Unexpected output: %s", m.Error())
}

@ -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))
}

@ -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 an NoValueErr but got %q instead", xerr)
}
c = loadChart(t, "testdata/subpop")

@ -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

@ -43,7 +43,7 @@ type Lint struct {
// LintResult is the result of Lint
type LintResult struct {
TotalChartsLinted int
Messages []support.Message
Messages []support.MessageError
Errors []error
}

@ -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
}

@ -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)
}

@ -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)
}

@ -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, ".") }

@ -238,7 +238,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.MessageError
go func() {
m = RunAll(malformedTemplate, values, namespace).Messages
ch <- 1

@ -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 []MessageError
// The highest severity of all the failing lint rules
HighestSeverity int
ChartDir string
}
// Message describes an error encountered while linting.
type Message struct {
type MessageError struct {
// Severity is one of the *Sev constants
Severity int
Path string
Err error
}
func (m Message) Error() string {
func (m MessageError) 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) MessageError {
return MessageError{Severity: severity, Path: path, Err: err}
}
// RunLinterRule returns true if the validation passed

@ -62,17 +62,17 @@ func TestRunLinterRule(t *testing.T) {
}
func TestMessage(t *testing.T) {
m := Message{ErrorSev, "Chart.yaml", errors.New("Foo")}
m := MessageError{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 = MessageError{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 = MessageError{InfoSev, "templates/rc.yaml", errors.New("FooBar")}
if m.Error() != "[INFO] templates/rc.yaml: FooBar" {
t.Errorf("Unexpected output: %s", m.Error())
}

@ -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))
}

@ -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 an NoValueErr but got %q instead", xerr)
}
c = loadChart(t, "testdata/subpop")

@ -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

@ -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

@ -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
}

@ -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 {

@ -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
}

Loading…
Cancel
Save