github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/channels/errors.go (about)

     1  package channels
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	"github.com/onflow/flow-go/model/flow"
     8  )
     9  
    10  // InvalidTopicErr error wrapper that indicates an error when checking if a Topic is a valid Flow Topic.
    11  type InvalidTopicErr struct {
    12  	topic Topic
    13  	err   error
    14  }
    15  
    16  func (e InvalidTopicErr) Error() string {
    17  	return fmt.Errorf("invalid topic %s: %w", e.topic, e.err).Error()
    18  }
    19  
    20  // NewInvalidTopicErr returns a new ErrMalformedTopic
    21  func NewInvalidTopicErr(topic Topic, err error) InvalidTopicErr {
    22  	return InvalidTopicErr{topic: topic, err: err}
    23  }
    24  
    25  // IsInvalidTopicErr returns true if an error is InvalidTopicErr
    26  func IsInvalidTopicErr(err error) bool {
    27  	var e InvalidTopicErr
    28  	return errors.As(err, &e)
    29  }
    30  
    31  // UnknownClusterIDErr error wrapper that indicates an invalid topic with an unknown cluster ID prefix.
    32  type UnknownClusterIDErr struct {
    33  	clusterId        flow.ChainID
    34  	activeClusterIds flow.ChainIDList
    35  }
    36  
    37  func (e UnknownClusterIDErr) Error() string {
    38  	return fmt.Errorf("cluster ID %s not found in active cluster IDs list %s", e.clusterId, e.activeClusterIds).Error()
    39  }
    40  
    41  // NewUnknownClusterIdErr returns a new UnknownClusterIDErr
    42  func NewUnknownClusterIdErr(clusterId flow.ChainID, activeClusterIds flow.ChainIDList) UnknownClusterIDErr {
    43  	return UnknownClusterIDErr{clusterId: clusterId, activeClusterIds: activeClusterIds}
    44  }
    45  
    46  // IsUnknownClusterIDErr returns true if an error is UnknownClusterIDErr
    47  func IsUnknownClusterIDErr(err error) bool {
    48  	var e UnknownClusterIDErr
    49  	return errors.As(err, &e)
    50  }