github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/fvm/errors/failures.go (about) 1 package errors 2 3 import ( 4 "github.com/onflow/flow-go/module/trace" 5 ) 6 7 func NewUnknownFailure(err error) CodedFailure { 8 return WrapCodedFailure( 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 ) CodedFailure { 20 return WrapCodedFailure( 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) CodedFailure { 30 return WrapCodedFailure( 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 HasFailureCode(err, FailureCodeLedgerFailure) 40 } 41 42 // NewStateMergeFailure constructs a new CodedError which captures a fatal 43 // caused by state merge. 44 func NewStateMergeFailure(err error) CodedFailure { 45 return WrapCodedFailure( 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) CodedFailure { 54 return WrapCodedFailure( 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 ) CodedFailure { 66 return NewCodedFailure( 67 FailureCodeParseRestrictedModeInvalidAccessFailure, 68 "cannot access %s while cadence is in parse restricted mode", 69 spanName) 70 } 71 72 // NewEVMFailure constructs a new CodedFailure which captures a fatal 73 // caused by the EVM. 74 func NewEVMFailure(err error) CodedFailure { 75 return WrapCodedFailure( 76 FailureCodeEVMFailure, 77 err, 78 "evm failure") 79 }