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

     1  package unicast
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  )
     7  
     8  // ErrMaxRetries  indicates retries completed with max retries without a successful attempt.
     9  type ErrMaxRetries struct {
    10  	attempts uint64
    11  	err      error
    12  }
    13  
    14  func (e ErrMaxRetries) Error() string {
    15  	return fmt.Errorf("retries failed max attempts reached %d: %w", e.attempts, e.err).Error()
    16  }
    17  
    18  // NewMaxRetriesErr returns a new ErrMaxRetries.
    19  func NewMaxRetriesErr(attempts uint64, err error) ErrMaxRetries {
    20  	return ErrMaxRetries{attempts: attempts, err: err}
    21  }
    22  
    23  // IsErrMaxRetries returns whether an error is ErrMaxRetries.
    24  func IsErrMaxRetries(err error) bool {
    25  	var e ErrMaxRetries
    26  	return errors.As(err, &e)
    27  }