errors

package
v0.29.4 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2023 License: AGPL-3.0 Imports: 9 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

This returns true if the error or one of its nested errors matches the specified error 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 IsALedgerFailure added in v0.21.0

func IsALedgerFailure(err error) bool

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

func IsAccountAccountPublicKeyNotFoundError

func IsAccountAccountPublicKeyNotFoundError(err error) bool

IsAccountAccountPublicKeyNotFoundError returns true if error has this type

func IsAccountNotFoundError

func IsAccountNotFoundError(err error) bool

IsAccountNotFoundError returns true if error has this type

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 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 IsInvalidEnvelopeSignatureError added in v0.28.0

func IsInvalidEnvelopeSignatureError(err error) bool

func IsInvalidPayloadSignatureError added in v0.28.0

func IsInvalidPayloadSignatureError(err error) bool

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 SplitErrorTypes

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

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

Types

type CodedError added in v0.28.0

type CodedError interface {
	Code() ErrorCode

	Unwrap() error

	error
}

func Find added in v0.28.0

func Find(err error, code ErrorCode) CodedError

This recursively unwraps the error and returns 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 NewBlockFinderFailure

func NewBlockFinderFailure(err error) CodedError

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

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 NewEncodingFailuref

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

NewEncodingFailuref formats and returns a new EncodingFailure

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 NewFrozenAccountError

func NewFrozenAccountError(address flow.Address) CodedError

NewFrozenAccountError constructs a new FrozenAccountError

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 NewInvalidFVMStateAccessError added in v0.29.0

func NewInvalidFVMStateAccessError(
	address flow.Address,
	path string,
	opType string,
) CodedError

NewInvalidFVMStateAccessError constructs a new CodedError which indicates that the cadence program attempted to directly access fvm'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 NewLedgerFailure

func NewLedgerFailure(err error) CodedError

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

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 NewParseRestrictedModeInvalidAccessFailure added in v0.28.0

func NewParseRestrictedModeInvalidAccessFailure(
	spanName trace.SpanName,
) CodedError

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,
) CodedError

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 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(
	owner string,
	key string,
	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 NewStateMergeFailure

func NewStateMergeFailure(err error) CodedError

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

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 NewUnknownFailure

func NewUnknownFailure(err error) CodedError

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 ErrorCode

type ErrorCode uint16
const (
	FailureCodeUnknownFailure     ErrorCode = 2000
	FailureCodeEncodingFailure    ErrorCode = 2001
	FailureCodeLedgerFailure      ErrorCode = 2002
	FailureCodeStateMergeFailure  ErrorCode = 2003
	FailureCodeBlockFinderFailure ErrorCode = 2004
	// Deprecated: No longer used.
	FailureCodeHasherFailure                           ErrorCode = 2005
	FailureCodeParseRestrictedModeInvalidAccessFailure ErrorCode = 2006
	FailureCodePayerBalanceCheckFailure                ErrorCode = 2007
	// Deprecated: No longer used.
	FailureCodeMetaTransactionFailure ErrorCode = 2100
)
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

	// 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
	ErrCodeScriptExecutionCancelledError             ErrorCode = 1114
	ErrCodeScriptExecutionTimedOutError              ErrorCode = 1113
	ErrCodeEventEncodingError                        ErrorCode = 1115
	ErrCodeInvalidFVMStateAccessError                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
	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
)

func (ErrorCode) IsFailure added in v0.28.0

func (ec ErrorCode) IsFailure() bool

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 FrozenAccountError

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

FrozenAccountError is returned when a frozen account signs a transaction

func (FrozenAccountError) Address

func (e FrozenAccountError) Address() flow.Address

Address returns the address of frozen account

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

Jump to

Keyboard shortcuts

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