diff --git a/.golangci.yml b/.golangci.yml index 161403d45a..8fc2ee8eeb 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -9,6 +9,7 @@ linters: - dogsled - durationcheck - errcheck + - errname - exportloopref - gochecknoinits - goprintffuncname diff --git a/pkg/background/common/errors.go b/pkg/background/common/errors.go index 68f48f9409..f8c6434190 100644 --- a/pkg/background/common/errors.go +++ b/pkg/background/common/errors.go @@ -2,65 +2,65 @@ package common import "fmt" -// ParseFailed stores the resource that failed to parse -type ParseFailed struct { +// ParseFailedError stores the resource that failed to parse +type ParseFailedError struct { spec interface{} parseError error } -func (e *ParseFailed) Error() string { +func (e *ParseFailedError) Error() string { return fmt.Sprintf("failed to parse the resource spec %v: %v", e.spec, e.parseError.Error()) } -//NewParseFailed returns a new ParseFailed error -func NewParseFailed(spec interface{}, err error) *ParseFailed { - return &ParseFailed{spec: spec, parseError: err} +// NewParseFailed returns a new ParseFailed error +func NewParseFailed(spec interface{}, err error) *ParseFailedError { + return &ParseFailedError{spec: spec, parseError: err} } -//Violation stores the rule that violated -type Violation struct { +// ViolationError stores the rule that violated +type ViolationError struct { rule string err error } -func (e *Violation) Error() string { +func (e *ViolationError) Error() string { return fmt.Sprintf("creating Violation; error %s", e.err) } -//NewViolation returns a new Violation error -func NewViolation(rule string, err error) *Violation { - return &Violation{rule: rule, err: err} +// NewViolation returns a new Violation error +func NewViolation(rule string, err error) *ViolationError { + return &ViolationError{rule: rule, err: err} } -// NotFound stores the resource that was not found -type NotFound struct { +// NotFoundError stores the resource that was not found +type NotFoundError struct { kind string namespace string name string } -func (e *NotFound) Error() string { +func (e *NotFoundError) Error() string { return fmt.Sprintf("resource %s/%s/%s not present", e.kind, e.namespace, e.name) } -//NewNotFound returns a new NotFound error -func NewNotFound(kind, namespace, name string) *NotFound { - return &NotFound{kind: kind, namespace: namespace, name: name} +// NewNotFound returns a new NotFound error +func NewNotFound(kind, namespace, name string) *NotFoundError { + return &NotFoundError{kind: kind, namespace: namespace, name: name} } -//ConfigNotFound stores the config information -type ConfigNotFound struct { +// ConfigNotFoundError stores the config information +type ConfigNotFoundError struct { config interface{} kind string namespace string name string } -func (e *ConfigNotFound) Error() string { +func (e *ConfigNotFoundError) Error() string { return fmt.Sprintf("configuration %v, not present in resource %s/%s/%s", e.config, e.kind, e.namespace, e.name) } //NewConfigNotFound returns a new NewConfigNotFound error -func NewConfigNotFound(config interface{}, kind, namespace, name string) *ConfigNotFound { - return &ConfigNotFound{config: config, kind: kind, namespace: namespace, name: name} +func NewConfigNotFound(config interface{}, kind, namespace, name string) *ConfigNotFoundError { + return &ConfigNotFoundError{config: config, kind: kind, namespace: namespace, name: name} } diff --git a/pkg/engine/context/mock_context.go b/pkg/engine/context/mock_context.go index 9b11ba45ae..2baf298df4 100644 --- a/pkg/engine/context/mock_context.go +++ b/pkg/engine/context/mock_context.go @@ -56,7 +56,7 @@ func (ctx *MockContext) Query(query string) (interface{}, error) { return emptyResult, nil } - return emptyResult, InvalidVariableErr{ + return emptyResult, InvalidVariableError{ variable: query, re: ctx.re, allowedPatterns: ctx.allowedPatterns, @@ -81,14 +81,14 @@ func (ctx *MockContext) getVariables() []string { return vars } -// InvalidVariableErr represents error for non-white-listed variables -type InvalidVariableErr struct { +// InvalidVariableError represents error for non-white-listed variables +type InvalidVariableError struct { variable string re *regexp.Regexp allowedPatterns []string } -func (i InvalidVariableErr) Error() string { +func (i InvalidVariableError) Error() string { if i.re == nil { return fmt.Sprintf("variable %s must match patterns %v", i.variable, i.allowedPatterns) } diff --git a/pkg/engine/variables/vars.go b/pkg/engine/variables/vars.go index df46c9f790..034f9d98b4 100644 --- a/pkg/engine/variables/vars.go +++ b/pkg/engine/variables/vars.go @@ -250,13 +250,13 @@ func validateElementInForEach(log logr.Logger) jsonUtils.Action { }) } -// NotResolvedReferenceErr is returned when it is impossible to resolve the variable -type NotResolvedReferenceErr struct { +// NotResolvedReferenceError is returned when it is impossible to resolve the variable +type NotResolvedReferenceError struct { reference string path string } -func (n NotResolvedReferenceErr) Error() string { +func (n NotResolvedReferenceError) Error() string { return fmt.Sprintf("NotResolvedReferenceErr,reference %s not resolved at path %s", n.reference, n.path) } @@ -278,7 +278,7 @@ func substituteReferencesIfAny(log logr.Logger) jsonUtils.Action { resolvedReference, err := resolveReference(log, data.Document, v, data.Path) if err != nil { switch err.(type) { - case context.InvalidVariableErr: + case context.InvalidVariableError: return nil, err default: return nil, fmt.Errorf("failed to resolve %v at path %s: %v", v, data.Path, err) @@ -304,7 +304,7 @@ func substituteReferencesIfAny(log logr.Logger) jsonUtils.Action { continue } - return data.Element, NotResolvedReferenceErr{ + return data.Element, NotResolvedReferenceError{ reference: v, path: data.Path, } @@ -368,7 +368,7 @@ func substituteVariablesIfAny(log logr.Logger, ctx context.EvalInterface, vr Var if err != nil { switch err.(type) { - case context.InvalidVariableErr, gojmespath.NotFoundError: + case context.InvalidVariableError, gojmespath.NotFoundError: return nil, err default: return nil, fmt.Errorf("failed to resolve %v at path %s: %v", variable, data.Path, err) diff --git a/pkg/policy/validate.go b/pkg/policy/validate.go index 8d87d8d5ca..b9e8354075 100644 --- a/pkg/policy/validate.go +++ b/pkg/policy/validate.go @@ -526,7 +526,7 @@ func checkNotFoundErr(err error) bool { switch err.(type) { case jmespath.NotFoundError: return true - case context.InvalidVariableErr: + case context.InvalidVariableError: return false default: return false