github.com/koko1123/flow-go-1@v0.29.6/fvm/errors/failures.go (about)

     1  package errors
     2  
     3  import (
     4  	"github.com/koko1123/flow-go-1/module/trace"
     5  )
     6  
     7  func NewUnknownFailure(err error) CodedError {
     8  	return WrapCodedError(
     9  		FailureCodeUnknownFailure,
    10  		err,
    11  		"unknown failure")
    12  }
    13  
    14  // NewEncodingFailuref formats and returns a new EncodingFailure
    15  func NewEncodingFailuref(
    16  	err error,
    17  	msg string,
    18  	args ...interface{},
    19  ) CodedError {
    20  	return WrapCodedError(
    21  		FailureCodeEncodingFailure,
    22  		err,
    23  		"encoding failed: "+msg,
    24  		args...)
    25  }
    26  
    27  // NewLedgerFailure constructs a new CodedError which captures a fatal error
    28  // cause by ledger failures.
    29  func NewLedgerFailure(err error) CodedError {
    30  	return WrapCodedError(
    31  		FailureCodeLedgerFailure,
    32  		err,
    33  		"ledger returns unsuccessful")
    34  }
    35  
    36  // IsLedgerFailure returns true if the error or any of the wrapped errors is
    37  // a ledger failure
    38  func IsLedgerFailure(err error) bool {
    39  	return HasErrorCode(err, FailureCodeLedgerFailure)
    40  }
    41  
    42  // NewStateMergeFailure constructs a new CodedError which captures a fatal
    43  // caused by state merge.
    44  func NewStateMergeFailure(err error) CodedError {
    45  	return WrapCodedError(
    46  		FailureCodeStateMergeFailure,
    47  		err,
    48  		"can not merge the state")
    49  }
    50  
    51  // NewBlockFinderFailure constructs a new CodedError which captures a fatal
    52  // caused by block finder.
    53  func NewBlockFinderFailure(err error) CodedError {
    54  	return WrapCodedError(
    55  		FailureCodeBlockFinderFailure,
    56  		err,
    57  		"can not retrieve the block")
    58  }
    59  
    60  // NewParseRestrictedModeInvalidAccessFailure constructs a CodedError which
    61  // captures a fatal caused by Cadence accessing an unexpected environment
    62  // operation while it is parsing programs.
    63  func NewParseRestrictedModeInvalidAccessFailure(
    64  	spanName trace.SpanName,
    65  ) CodedError {
    66  	return NewCodedError(
    67  		FailureCodeParseRestrictedModeInvalidAccessFailure,
    68  		"cannot access %s while cadence is in parse restricted mode",
    69  		spanName)
    70  }