github.com/cilium/cilium@v1.16.2/pkg/endpointmanager/errors.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package endpointmanager
     5  
     6  import (
     7  	"errors"
     8  )
     9  
    10  var (
    11  	// ErrUnsupportedID represents an error of unsupported IP address format.
    12  	ErrUnsupportedID = errors.New("unsupported IP address format")
    13  )
    14  
    15  // ErrInvalidPrefix represents the error of an invalid prefix.
    16  type ErrInvalidPrefix struct {
    17  	// InvalidPrefix contains the invalid prefix.
    18  	InvalidPrefix string
    19  }
    20  
    21  // Error returns the string representation of the ErrInvalidPrefix.
    22  func (e ErrInvalidPrefix) Error() string {
    23  	return "unknown endpoint prefix '" + e.InvalidPrefix + "'"
    24  }
    25  
    26  // IsErrUnsupportedID returns true if the given error is the type of
    27  // ErrUnsupportedID.
    28  func IsErrUnsupportedID(err error) bool {
    29  	return errors.Is(err, ErrUnsupportedID)
    30  }
    31  
    32  // IsErrInvalidPrefix returns true if the given error is the type of
    33  // ErrInvalidPrefix.
    34  func IsErrInvalidPrefix(err error) bool {
    35  	var errInvalidPrefix ErrInvalidPrefix
    36  	return errors.As(err, &errInvalidPrefix)
    37  }