github.com/cilium/cilium@v1.16.2/pkg/k8s/apis/cilium.io/v2/errors.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package v2
     5  
     6  var (
     7  	// ErrEmptyCNP is an error representing a CNP that is empty, which means it is
     8  	// missing both a `spec` and `specs` (both are nil).
     9  	ErrEmptyCNP = NewErrParse("Invalid CiliumNetworkPolicy spec(s): empty policy")
    10  
    11  	// ErrEmptyCCNP is an error representing a CCNP that is empty, which means it is
    12  	// missing both a `spec` and `specs` (both are nil).
    13  	ErrEmptyCCNP = NewErrParse("Invalid CiliumClusterwideNetworkPolicy spec(s): empty policy")
    14  
    15  	// ParsingErr is for comparison when checking error types.
    16  	ParsingErr = NewErrParse("")
    17  )
    18  
    19  // ErrParse is an error to describe where policy fails to parse due any invalid
    20  // rule.
    21  //
    22  // +k8s:deepcopy-gen=false
    23  // +deepequal-gen=false
    24  type ErrParse struct {
    25  	msg string
    26  }
    27  
    28  // NewErrParse returns a new ErrParse.
    29  func NewErrParse(msg string) ErrParse {
    30  	return ErrParse{
    31  		msg: msg,
    32  	}
    33  }
    34  
    35  // Error returns the error message for parsing
    36  func (e ErrParse) Error() string {
    37  	return e.msg
    38  }
    39  
    40  // Is returns true if the given error is the type of 'ErrParse'.
    41  func (_ ErrParse) Is(e error) bool {
    42  	_, ok := e.(ErrParse)
    43  	return ok
    44  }