errors

package
v0.33.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2024 License: AGPL-3.0 Imports: 8 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target interface{}) bool

As is a utility function to call std error lib `As` function. As finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true. Otherwise, it returns false. The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.

func HandleRuntimeError

func HandleRuntimeError(err error) error

HandleRuntimeError handles runtime errors and separates errors generated by runtime from fvm errors (e.g. environment errors)

func HasErrorCode added in v0.28.0

func HasErrorCode(err error, code ErrorCode) bool

HasErrorCode returns true if the error or one of its nested errors matches the specified error code.

func HasFailureCode added in v0.33.7

func HasFailureCode(err error, code FailureCode) bool

HasFailureCode returns true if the error or one of its nested errors matches the specified failure code.

func Is

func Is(err error, target error) bool

Is is a utility function to call std error lib `Is` function for instance equality checks.

func IsAccountNotFoundError

func IsAccountNotFoundError(err error) bool

IsAccountNotFoundError returns true if error has this type

func IsAccountPublicKeyNotFoundError added in v0.30.0

func IsAccountPublicKeyNotFoundError(err error) bool

IsAccountPublicKeyNotFoundError returns true if error has this type

func IsBlockHeightOutOfRangeError added in v0.33.15

func IsBlockHeightOutOfRangeError(err error) bool

func IsCadenceRuntimeError

func IsCadenceRuntimeError(err error) bool

func IsComputationLimitExceededError added in v0.25.2

func IsComputationLimitExceededError(err error) bool

IsComputationLimitExceededError returns true if error has this code.

func IsEVMError added in v0.33.1

func IsEVMError(err error) bool

IsEVMError returns true if error is an EVM error

func IsFailure added in v0.28.0

func IsFailure(err error) bool

IsFailure returns true if the error is un-coded, or if the error contains a failure code.

func IsInsufficientPayerBalanceError added in v0.29.0

func IsInsufficientPayerBalanceError(err error) bool

IsInsufficientPayerBalanceError returns true if error has this code.

func IsInvalidArgumentError added in v0.30.0

func IsInvalidArgumentError(err error) bool

func IsInvalidEnvelopeSignatureError added in v0.28.0

func IsInvalidEnvelopeSignatureError(err error) bool

func IsInvalidPayloadSignatureError added in v0.28.0

func IsInvalidPayloadSignatureError(err error) bool

func IsLedgerFailure added in v0.30.0

func IsLedgerFailure(err error) bool

IsLedgerFailure returns true if the error or any of the wrapped errors is a ledger failure

func IsLedgerInteractionLimitExceededError added in v0.28.0

func IsLedgerInteractionLimitExceededError(err error) bool

func IsMemoryLimitExceededError added in v0.25.2

func IsMemoryLimitExceededError(err error) bool

IsMemoryLimitExceededError returns true if error has this code.

func IsOperationNotSupportedError added in v0.28.0

func IsOperationNotSupportedError(err error) bool

func IsStorageCapacityExceededError added in v0.28.0

func IsStorageCapacityExceededError(err error) bool

func IsTransactionFeeDeductionFailedError added in v0.29.0

func IsTransactionFeeDeductionFailedError(err error) bool

IsTransactionFeeDeductionFailedError returns true if error has this code.

func IsValueError added in v0.28.0

func IsValueError(err error) bool

func NewCodedError added in v0.28.0

func NewCodedError(
	code ErrorCode,
	format string,
	formatArguments ...interface{},
) codedError

func NewCodedFailure added in v0.33.7

func NewCodedFailure(
	code FailureCode,
	format string,
	formatArguments ...interface{},
) codedFailure

func SplitErrorTypes

func SplitErrorTypes(inp error) (err CodedError, failure CodedFailure)

SplitErrorTypes splits the error into fatal (failures) and non-fatal errors

func WrapCodedError added in v0.28.0

func WrapCodedError(
	code ErrorCode,
	err error,
	prefixMsgFormat string,
	formatArguments ...interface{},
) codedError

func WrapCodedFailure added in v0.33.7

func WrapCodedFailure(
	code FailureCode,
	err error,
	prefixMsgFormat string,
	formatArguments ...interface{},
) codedFailure

Types

type CodedError added in v0.28.0

type CodedError interface {
	Code() ErrorCode

	Unwrappable
	error
}

func Find added in v0.28.0

func Find(originalErr error, code ErrorCode) CodedError

Find recursively unwraps the error and returns the first CodedError that matches the specified error code.

func NewAccountAlreadyExistsError

func NewAccountAlreadyExistsError(address flow.Address) CodedError

NewAccountAlreadyExistsError constructs a new CodedError. It is returned when account creation fails because another account already exist at that address.

TODO maybe this should be failure since user has no control over this

func NewAccountAuthorizationErrorf

func NewAccountAuthorizationErrorf(
	address flow.Address,
	msg string,
	args ...interface{},
) CodedError

NewAccountAuthorizationErrorf constructs a new CodedError which indicates that an authorization issue either:

  • a transaction is missing a required signature to authorize access to an account, or
  • a transaction doesn't have authorization to performe some operations like account creation.

func NewAccountNotFoundError

func NewAccountNotFoundError(address flow.Address) CodedError

func NewAccountPublicKeyLimitError added in v0.27.0

func NewAccountPublicKeyLimitError(
	address flow.Address,
	counts uint64,
	limit uint64,
) CodedError

NewAccountPublicKeyLimitError constructs a new CodedError. It is returned when an account tries to add public keys over the limit.

func NewAccountPublicKeyNotFoundError

func NewAccountPublicKeyNotFoundError(
	address flow.Address,
	keyIndex uint64,
) CodedError

NewAccountPublicKeyNotFoundError constructs a new CodedError. It is returned when a public key not found for the given address and key index.

func NewBlockHeightOutOfRangeError added in v0.33.15

func NewBlockHeightOutOfRangeError(height uint64) CodedError

func NewCadenceRuntimeError

func NewCadenceRuntimeError(err runtime.Error) CodedError

NewCadenceRuntimeError constructs a new CodedError which captures a collection of errors provided by cadence runtime. It cover cadence errors such as:

NotDeclaredError, NotInvokableError, ArgumentCountError, TransactionNotDeclaredError, ConditionError, RedeclarationError, DereferenceError, OverflowError, UnderflowError, DivisionByZeroError, DestroyedCompositeError, ForceAssignmentToNonNilResourceError, ForceNilError, TypeMismatchError, InvalidPathDomainError, OverwriteError, CyclicLinkError, ArrayIndexOutOfBoundsError, ...

The Cadence error might have occurred because of an inner fvm Error.

func NewComputationLimitExceededError added in v0.25.2

func NewComputationLimitExceededError(limit uint64) CodedError

NewComputationLimitExceededError constructs a new CodedError which indicates that computation has exceeded its limit.

func NewContractNotFoundError

func NewContractNotFoundError(
	address flow.Address,
	contract string,
) CodedError

NewContractNotFoundError constructs a new ErrContractNotFoundError error

func NewCouldNotGetExecutionParameterFromStateError added in v0.25.2

func NewCouldNotGetExecutionParameterFromStateError(
	address string,
	path string,
) CodedError

NewCouldNotGetExecutionParameterFromStateError constructs a new CodedError which indicates that computation has exceeded its limit.

func NewEventEncodingError added in v0.29.0

func NewEventEncodingError(err error) CodedError

NewEventEncodingError construct a new CodedError which indicates that encoding event has failed

func NewEventLimitExceededError

func NewEventLimitExceededError(
	totalByteSize uint64,
	limit uint64) CodedError

NewEventLimitExceededError constructs a CodedError which indicates that the transaction has produced events with size more than limit.

func NewInsufficientPayerBalanceError added in v0.29.0

func NewInsufficientPayerBalanceError(
	payer flow.Address,
	requiredBalance cadence.UFix64,
) CodedError

NewInsufficientPayerBalanceError constructs a new CodedError which indicates that the payer has insufficient balance to attempt transaction execution.

func NewInvalidAddressErrorf

func NewInvalidAddressErrorf(
	address flow.Address,
	msg string,
	args ...interface{},
) CodedError

NewInvalidAddressErrorf constructs a new CodedError which indicates that a transaction references an invalid flow Address in either the Authorizers or Payer field.

func NewInvalidArgumentErrorf

func NewInvalidArgumentErrorf(msg string, args ...interface{}) CodedError

NewInvalidArgumentErrorf constructs a new CodedError which indicates that a transaction includes invalid arguments. This error is the result of failure in any of the following conditions: - number of arguments doesn't match the template

TODO add more cases like argument size

func NewInvalidEnvelopeSignatureError

func NewInvalidEnvelopeSignatureError(
	txnSig flow.TransactionSignature,
	err error,
) CodedError

NewInvalidEnvelopeSignatureError constructs a new CodedError which indicates that signature verification for a envelope key in this transaction has failed. Tthis error is the result of failure in any of the following conditions: - provided hashing method is not supported - signature size or format is invalid - signature verification failed

func NewInvalidInternalStateAccessError added in v0.30.0

func NewInvalidInternalStateAccessError(
	id flow.RegisterID,
	opType string,
) CodedError

NewInvalidInternalStateAccessError constructs a new CodedError which indicates that the cadence program attempted to directly access flow's internal state.

func NewInvalidLocationErrorf

func NewInvalidLocationErrorf(
	location runtime.Location,
	msg string,
	args ...interface{},
) CodedError

NewInvalidLocationErrorf constructs a new CodedError which indicates an invalid location is passed.

func NewInvalidPayloadSignatureError

func NewInvalidPayloadSignatureError(
	txnSig flow.TransactionSignature,
	err error,
) CodedError

NewInvalidPayloadSignatureError constructs a new CodedError which indicates that signature verification for a key in this transaction has failed. This error is the result of failure in any of the following conditions: - provided hashing method is not supported - signature size or format is invalid - signature verification failed

func NewInvalidProposalSeqNumberError

func NewInvalidProposalSeqNumberError(
	proposal flow.ProposalKey,
	currentSeqNumber uint64,
) CodedError

NewInvalidProposalSeqNumberError constructs a new InvalidProposalSeqNumberError

func NewInvalidProposalSignatureError

func NewInvalidProposalSignatureError(
	proposal flow.ProposalKey,
	err error,
) CodedError

NewInvalidProposalSignatureError constructs a new CodedError which indicates that no valid signature is provided for the proposal key.

func NewLedgerInteractionLimitExceededError added in v0.27.0

func NewLedgerInteractionLimitExceededError(
	used uint64,
	limit uint64,
) CodedError

NewLedgerInteractionLimitExceededError constructs a CodeError. It is returned when a tx hits the maximum ledger interaction limit.

func NewMemoryLimitExceededError added in v0.25.2

func NewMemoryLimitExceededError(limit uint64) CodedError

NewMemoryLimitExceededError constructs a new CodedError which indicates that execution has exceeded its memory limits.

func NewOperationAuthorizationErrorf

func NewOperationAuthorizationErrorf(
	operation string,
	msg string,
	args ...interface{},
) CodedError

NewOperationAuthorizationErrorf constructs a new CodedError which indicates not enough authorization to perform an operations like account creation or smart contract deployment.

func NewOperationNotSupportedError

func NewOperationNotSupportedError(operation string) CodedError

NewOperationNotSupportedError construct a new CodedError. It is generated when an operation (e.g. getting block info) is not supported in the current environment.

func NewScriptExecutionCancelledError added in v0.26.0

func NewScriptExecutionCancelledError(err error) CodedError

NewScriptExecutionCancelledError construct a new CodedError which indicates that Cadence Script execution has been cancelled (e.g. request connection has been droped)

note: this error is used by scripts only and won't be emitted for transactions since transaction execution has to be deterministic.

func NewScriptExecutionTimedOutError added in v0.26.0

func NewScriptExecutionTimedOutError() CodedError

NewScriptExecutionTimedOutError construct a new CodedError which indicates that Cadence Script execution has been taking more time than what is allowed.

note: this error is used by scripts only and won't be emitted for transactions since transaction execution has to be deterministic.

func NewStateKeySizeLimitError

func NewStateKeySizeLimitError(
	id flow.RegisterID,
	size uint64,
	limit uint64,
) CodedError

NewStateKeySizeLimitError constructs a CodedError which indicates that the provided key has exceeded the size limit allowed by the storage.

func NewStateValueSizeLimitError

func NewStateValueSizeLimitError(
	value flow.RegisterValue,
	size uint64,
	limit uint64,
) CodedError

NewStateValueSizeLimitError constructs a CodedError which indicates that the provided value has exceeded the size limit allowed by the storage.

func NewStorageCapacityExceededError

func NewStorageCapacityExceededError(
	address flow.Address,
	storageUsed uint64,
	storageCapacity uint64,
) CodedError

NewStorageCapacityExceededError constructs a new CodedError which indicates that an account used more storage than it has storage capacity.

func NewTransactionFeeDeductionFailedError added in v0.17.1

func NewTransactionFeeDeductionFailedError(
	payer flow.Address,
	txFees uint64,
	err error,
) CodedError

NewTransactionFeeDeductionFailedError constructs a new CodedError which indicates that a there was an error deducting transaction fees from the transaction Payer

func NewValueErrorf

func NewValueErrorf(
	valueStr string,
	msg string,
	args ...interface{},
) CodedError

NewValueErrorf constructs a new CodedError which indicates a value is not valid value.

type CodedFailure added in v0.33.7

type CodedFailure interface {
	Code() FailureCode

	Unwrappable
	error
}

func AsFailure added in v0.33.7

func AsFailure(err error) CodedFailure

func FindFailure added in v0.33.7

func FindFailure(originalErr error, code FailureCode) CodedFailure

FindFailure recursively unwraps the error and returns the first CodedFailure that matches the specified error code.

func NewBlockFinderFailure

func NewBlockFinderFailure(err error) CodedFailure

NewBlockFinderFailure constructs a new CodedError which captures a fatal caused by block finder.

func NewDerivedDataCacheImplementationFailure added in v0.30.0

func NewDerivedDataCacheImplementationFailure(
	err error,
) CodedFailure

NewDerivedDataCacheImplementationFailure indicate an implementation error in the derived data cache.

func NewEncodingFailuref

func NewEncodingFailuref(
	err error,
	msg string,
	args ...interface{},
) CodedFailure

NewEncodingFailuref formats and returns a new EncodingFailure

func NewLedgerFailure

func NewLedgerFailure(err error) CodedFailure

NewLedgerFailure constructs a new CodedError which captures a fatal error cause by ledger failures.

func NewParseRestrictedModeInvalidAccessFailure added in v0.28.0

func NewParseRestrictedModeInvalidAccessFailure(
	spanName trace.SpanName,
) CodedFailure

NewParseRestrictedModeInvalidAccessFailure constructs a CodedError which captures a fatal caused by Cadence accessing an unexpected environment operation while it is parsing programs.

func NewPayerBalanceCheckFailure added in v0.29.0

func NewPayerBalanceCheckFailure(
	payer flow.Address,
	err error,
) CodedFailure

indicates that a there was an error checking the payers balance. This is an implementation error most likely between the smart contract and FVM interaction and should not happen in regular execution.

func NewRandomSourceFailure added in v0.32.2

func NewRandomSourceFailure(
	err error,
) CodedFailure

NewRandomSourceFailure indicate an implementation error in the random source provider.

func NewStateMergeFailure

func NewStateMergeFailure(err error) CodedFailure

NewStateMergeFailure constructs a new CodedError which captures a fatal caused by state merge.

func NewUnknownFailure

func NewUnknownFailure(err error) CodedFailure

type EVMError added in v0.33.1

type EVMError struct {
	CodedError
}

func NewEVMError added in v0.33.1

func NewEVMError(err error) EVMError

NewEVMError constructs a new CodedError which captures a collection of errors provided by (non-fatal) evm runtime.

func (EVMError) IsUserError added in v0.33.1

func (e EVMError) IsUserError()

type ErrorCode

type ErrorCode uint16
const (
	// tx validation errors 1000 - 1049
	// Deprecated: no longer in use
	ErrCodeTxValidationError ErrorCode = 1000
	// Deprecated: No longer used.
	ErrCodeInvalidTxByteSizeError ErrorCode = 1001
	// Deprecated: No longer used.
	ErrCodeInvalidReferenceBlockError ErrorCode = 1002
	// Deprecated: No longer used.
	ErrCodeExpiredTransactionError ErrorCode = 1003
	// Deprecated: No longer used.
	ErrCodeInvalidScriptError ErrorCode = 1004
	// Deprecated: No longer used.
	ErrCodeInvalidGasLimitError          ErrorCode = 1005
	ErrCodeInvalidProposalSignatureError ErrorCode = 1006
	ErrCodeInvalidProposalSeqNumberError ErrorCode = 1007
	ErrCodeInvalidPayloadSignatureError  ErrorCode = 1008
	ErrCodeInvalidEnvelopeSignatureError ErrorCode = 1009

	// base errors 1050 - 1100
	// Deprecated: No longer used.
	ErrCodeFVMInternalError            ErrorCode = 1050
	ErrCodeValueError                  ErrorCode = 1051
	ErrCodeInvalidArgumentError        ErrorCode = 1052
	ErrCodeInvalidAddressError         ErrorCode = 1053
	ErrCodeInvalidLocationError        ErrorCode = 1054
	ErrCodeAccountAuthorizationError   ErrorCode = 1055
	ErrCodeOperationAuthorizationError ErrorCode = 1056
	ErrCodeOperationNotSupportedError  ErrorCode = 1057
	ErrCodeBlockHeightOutOfRangeError  ErrorCode = 1058

	// execution errors 1100 - 1200
	// Deprecated: No longer used.
	ErrCodeExecutionError      ErrorCode = 1100
	ErrCodeCadenceRunTimeError ErrorCode = 1101
	// Deprecated: No longer used.
	ErrCodeEncodingUnsupportedValue ErrorCode = 1102
	ErrCodeStorageCapacityExceeded  ErrorCode = 1103
	// Deprecated: No longer used.
	ErrCodeGasLimitExceededError                     ErrorCode = 1104
	ErrCodeEventLimitExceededError                   ErrorCode = 1105
	ErrCodeLedgerInteractionLimitExceededError       ErrorCode = 1106
	ErrCodeStateKeySizeLimitError                    ErrorCode = 1107
	ErrCodeStateValueSizeLimitError                  ErrorCode = 1108
	ErrCodeTransactionFeeDeductionFailedError        ErrorCode = 1109
	ErrCodeComputationLimitExceededError             ErrorCode = 1110
	ErrCodeMemoryLimitExceededError                  ErrorCode = 1111
	ErrCodeCouldNotDecodeExecutionParameterFromState ErrorCode = 1112
	ErrCodeScriptExecutionTimedOutError              ErrorCode = 1113
	ErrCodeScriptExecutionCancelledError             ErrorCode = 1114
	ErrCodeEventEncodingError                        ErrorCode = 1115
	ErrCodeInvalidInternalStateAccessError           ErrorCode = 1116
	// 1117 was never deployed and is free to use
	ErrCodeInsufficientPayerBalance ErrorCode = 1118

	// accounts errors 1200 - 1250
	// Deprecated: No longer used.
	ErrCodeAccountError                  ErrorCode = 1200
	ErrCodeAccountNotFoundError          ErrorCode = 1201
	ErrCodeAccountPublicKeyNotFoundError ErrorCode = 1202
	ErrCodeAccountAlreadyExistsError     ErrorCode = 1203
	// Deprecated: No longer used.
	ErrCodeFrozenAccountError ErrorCode = 1204
	// Deprecated: No longer used.
	ErrCodeAccountStorageNotInitializedError ErrorCode = 1205
	ErrCodeAccountPublicKeyLimitError        ErrorCode = 1206

	// contract errors 1250 - 1300
	// Deprecated: No longer used.
	ErrCodeContractError         ErrorCode = 1250
	ErrCodeContractNotFoundError ErrorCode = 1251
	// Deprecated: No longer used.
	ErrCodeContractNamesNotFoundError ErrorCode = 1252

	// fvm std lib errors 1300-1400
	ErrEVMExecutionError ErrorCode = 1300
)

func (ErrorCode) String

func (ec ErrorCode) String() string

type ErrorsCollector added in v0.29.0

type ErrorsCollector struct {
	// contains filtered or unexported fields
}

Utility object for collecting Processor errors.

func NewErrorsCollector added in v0.29.0

func NewErrorsCollector() *ErrorsCollector

func (*ErrorsCollector) Collect added in v0.29.0

func (collector *ErrorsCollector) Collect(err error) *ErrorsCollector

This returns collector for chaining purposes.

func (*ErrorsCollector) CollectedError added in v0.29.0

func (collector *ErrorsCollector) CollectedError() bool

func (*ErrorsCollector) CollectedFailure added in v0.29.0

func (collector *ErrorsCollector) CollectedFailure() bool

func (*ErrorsCollector) ErrorOrNil added in v0.29.0

func (collector *ErrorsCollector) ErrorOrNil() error

type FailureCode

type FailureCode uint16
const (
	FailureCodeUnknownFailure     FailureCode = 2000
	FailureCodeEncodingFailure    FailureCode = 2001
	FailureCodeLedgerFailure      FailureCode = 2002
	FailureCodeStateMergeFailure  FailureCode = 2003
	FailureCodeBlockFinderFailure FailureCode = 2004
	// Deprecated: No longer used.
	FailureCodeHasherFailure                           FailureCode = 2005
	FailureCodeParseRestrictedModeInvalidAccessFailure FailureCode = 2006
	FailureCodePayerBalanceCheckFailure                FailureCode = 2007
	FailureCodeDerivedDataCacheImplementationFailure   FailureCode = 2008
	FailureCodeRandomSourceFailure                     FailureCode = 2009
	// Deprecated: No longer used.
	FailureCodeMetaTransactionFailure FailureCode = 2100
)

func (FailureCode) String

func (fc FailureCode) String() string

type InvalidProposalSeqNumberError

type InvalidProposalSeqNumberError struct {
	CodedError
	// contains filtered or unexported fields
}

InvalidProposalSeqNumberError indicates that proposal key sequence number does not match the on-chain value.

func (InvalidProposalSeqNumberError) CurrentSeqNumber

func (e InvalidProposalSeqNumberError) CurrentSeqNumber() uint64

CurrentSeqNumber returns the current sequence number

func (InvalidProposalSeqNumberError) ProvidedSeqNumber added in v0.16.0

func (e InvalidProposalSeqNumberError) ProvidedSeqNumber() uint64

ProvidedSeqNumber returns the provided sequence number

type Unwrappable added in v0.30.0

type Unwrappable interface {
	error
	Unwrap() error
}

type UnwrappableErrors added in v0.33.7

type UnwrappableErrors interface {
	error
	Unwrap() []error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL