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

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Hubble
     3  
     4  package errors
     5  
     6  import (
     7  	"errors"
     8  	"fmt"
     9  )
    10  
    11  var (
    12  	// ErrEmptyData gets returns when monitoring payload contained no data
    13  	ErrEmptyData = errors.New("empty data")
    14  	// ErrUnknownEventType is returned if the monitor event is an unknown type
    15  	ErrUnknownEventType = errors.New("unknown event type")
    16  	// ErrInvalidAgentMessageType is returned if an agent message is of invalid type
    17  	ErrInvalidAgentMessageType = errors.New("invalid agent message type")
    18  	// ErrEventSkipped is returned when an event was skipped (e.g. due to configuration
    19  	// or incomplete data)
    20  	ErrEventSkipped = errors.New("event was skipped")
    21  )
    22  
    23  // ErrInvalidType specifies when it was given a packet type that was not
    24  // possible to be decoded by the decoder.
    25  type ErrInvalidType struct {
    26  	invalidType byte
    27  }
    28  
    29  // NewErrInvalidType returns a new ErrInvalidType
    30  func NewErrInvalidType(invalidType byte) error {
    31  	return ErrInvalidType{invalidType: invalidType}
    32  }
    33  
    34  func (e ErrInvalidType) Error() string {
    35  	return fmt.Sprintf("can't decode following payload type: %v", e.invalidType)
    36  }
    37  
    38  // IsErrInvalidType returns true if the given error is type of ErrInvalidType
    39  func IsErrInvalidType(err error) bool {
    40  	var errInvalidType ErrInvalidType
    41  	return errors.As(err, &errInvalidType)
    42  }