mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-05 15:37:19 +00:00
chore: enable errname linter (#3926)
Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
This commit is contained in:
parent
0bf201dba2
commit
d7a3ba596d
5 changed files with 35 additions and 34 deletions
|
@ -9,6 +9,7 @@ linters:
|
|||
- dogsled
|
||||
- durationcheck
|
||||
- errcheck
|
||||
- errname
|
||||
- exportloopref
|
||||
- gochecknoinits
|
||||
- goprintffuncname
|
||||
|
|
|
@ -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}
|
||||
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}
|
||||
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}
|
||||
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}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue