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

     1  package execution_data
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	"github.com/ipfs/go-cid"
     8  )
     9  
    10  // MalformedDataError is returned when malformed data is found at some level of the requested
    11  // blob tree. It likely indicates that the tree was generated incorrectly, and hence the request
    12  // should not be retried.
    13  type MalformedDataError struct {
    14  	err error
    15  }
    16  
    17  func NewMalformedDataError(err error) *MalformedDataError {
    18  	return &MalformedDataError{err: err}
    19  }
    20  
    21  func (e *MalformedDataError) Error() string {
    22  	return fmt.Sprintf("malformed data: %v", e.err)
    23  }
    24  
    25  func (e *MalformedDataError) Unwrap() error { return e.err }
    26  
    27  // IsMalformedDataError returns whether an error is MalformedDataError
    28  func IsMalformedDataError(err error) bool {
    29  	var malformedDataErr *MalformedDataError
    30  	return errors.As(err, &malformedDataErr)
    31  }
    32  
    33  // BlobNotFoundError is returned when a blob could not be found.
    34  type BlobNotFoundError struct {
    35  	cid cid.Cid
    36  }
    37  
    38  func NewBlobNotFoundError(cid cid.Cid) *BlobNotFoundError {
    39  	return &BlobNotFoundError{cid: cid}
    40  }
    41  
    42  func (e *BlobNotFoundError) Error() string {
    43  	return fmt.Sprintf("blob %v not found", e.cid.String())
    44  }
    45  
    46  // IsBlobNotFoundError returns whether an error is BlobNotFoundError
    47  func IsBlobNotFoundError(err error) bool {
    48  	var blobNotFoundError *BlobNotFoundError
    49  	return errors.As(err, &blobNotFoundError)
    50  }
    51  
    52  // BlobSizeLimitExceededError is returned when a blob exceeds the maximum size allowed.
    53  type BlobSizeLimitExceededError struct {
    54  	cid cid.Cid
    55  }
    56  
    57  func (e *BlobSizeLimitExceededError) Error() string {
    58  	return fmt.Sprintf("blob %v exceeds maximum blob size", e.cid.String())
    59  }
    60  
    61  // IsBlobSizeLimitExceededError returns whether an error is BlobSizeLimitExceededError
    62  func IsBlobSizeLimitExceededError(err error) bool {
    63  	var blobSizeLimitExceededError *BlobSizeLimitExceededError
    64  	return errors.As(err, &blobSizeLimitExceededError)
    65  }