Source Code Survey
This page provides a very high level, sometimes "pseudocode", view of error types and related messages as implemented by the NEAR platform.
Errors raised by the NEAR platform are implemented in the following locations in nearcore
:
RuntimeError and subtypes
RuntimeError
Definition
/// Error returned from `Runtime::apply`
pub enum RuntimeError {
/// An unexpected integer overflow occurred. The likely issue is an invalid state or the transition.
UnexpectedIntegerOverflow,
/// An error happened during TX verification and account charging. It's likely the chunk is invalid.
/// and should be challenged.
InvalidTxError(InvalidTxError),
/// Unexpected error which is typically related to the node storage corruption.account
/// That it's possible the input state is invalid or malicious.
StorageError(StorageError),
/// An error happens if `check_balance` fails, which is likely an indication of an invalid state.
BalanceMismatchError(BalanceMismatchError),
}
Error Messages
- see below:
InvalidTxError
,StorageError
andBalanceMismatchError
InvalidTxError
Definition
/// An error happened during TX execution
pub enum InvalidTxError {
/// Happens if a wrong AccessKey used or AccessKey has not enough permissions
InvalidAccessKeyError(InvalidAccessKeyError),
/// TX signer_id is not in a valid format or not satisfy requirements see `near_core::primitives::utils::is_valid_account_id`
InvalidSignerId { signer_id: AccountId },
/// TX signer_id is not found in a storage
SignerDoesNotExist { signer_id: AccountId },
/// Transaction nonce must be account[access_key].nonce + 1
InvalidNonce { tx_nonce: Nonce, ak_nonce: Nonce },
/// TX receiver_id is not in a valid format or not satisfy requirements see `near_core::primitives::utils::is_valid_account_id`
InvalidReceiverId { receiver_id: AccountId },
/// TX signature is not valid
InvalidSignature,
/// Account does not have enough balance to cover TX cost
NotEnoughBalance {
signer_id: AccountId,
balance: NearToken,
cost: NearToken,
},
/// Signer account rent is unpaid
RentUnpaid {
/// An account which is required to pay the rent
signer_id: AccountId,
/// Required balance to cover the state rent
amount: NearToken,
},
/// An integer overflow occurred during transaction cost estimation.
CostOverflow,
/// Transaction parent block hash doesn't belong to the current chain
InvalidChain,
/// Transaction has expired
Expired,
/// An error occurred while validating actions of a Transaction.
ActionsValidation(ActionsValidationError),
}
Error Messages
InvalidTxError::InvalidSignerId { signer_id }
"Invalid signer account ID {:?} according to requirements"
InvalidTxError::SignerDoesNotExist { signer_id }
"Signer {:?} does not exist"
InvalidTxError::InvalidAccessKeyError(access_key_error)
InvalidTxError::InvalidNonce { tx_nonce, ak_nonce }
"Transaction nonce {} must be larger than nonce of the used access key {}"
InvalidTxError::InvalidReceiverId { receiver_id }
"Invalid receiver account ID {:?} according to requirements"
InvalidTxError::InvalidSignature
"Transaction is not signed with the given public key"
InvalidTxError::NotEnoughBalance { signer_id, balance, cost }
"Sender {:?} does not have enough balance {} for operation costing {}"
InvalidTxError::RentUnpaid { signer_id, amount }
"Failed to execute, because the account {:?} wouldn't have enough to pay required rent {}"
InvalidTxError::CostOverflow
"Transaction gas or balance cost is too high"
InvalidTxError::InvalidChain
"Transaction parent block hash doesn't belong to the current chain"
InvalidTxError::Expired
"Transaction has expired"
InvalidTxError::ActionsValidation(error)
"Transaction actions validation error: {}"
StorageError
Definition
pub enum StorageError {
/// Key-value db internal failure
StorageInternalError,
/// Storage is PartialStorage and requested a missing trie node
TrieNodeMissing,
/// Either invalid state or key-value db is corrupted.
/// For PartialStorage it cannot be corrupted.
/// Error message is unreliable and for debugging purposes only. It's also probably ok to
/// panic in every place that produces this error.
/// We can check if db is corrupted by verifying everything in the state trie.
StorageInconsistentState(String),
}
BalanceMismatchError
Definition
/// Happens when the input balance doesn't match the output balance in Runtime apply.
pub struct BalanceMismatchError {
// Input balances
pub incoming_validator_rewards: NearToken,
pub initial_accounts_balance: NearToken,
pub incoming_receipts_balance: NearToken,
pub processed_delayed_receipts_balance: NearToken,
pub initial_postponed_receipts_balance: NearToken,
// Output balances
pub final_accounts_balance: NearToken,
pub outgoing_receipts_balance: NearToken,
pub new_delayed_receipts_balance: NearToken,
pub final_postponed_receipts_balance: NearToken,
pub total_rent_paid: NearToken,
pub total_validator_reward: NearToken,
pub total_balance_burnt: NearToken,
pub total_balance_slashed: NearToken,
}
Error Messages
"Balance Mismatch Error. The input balance {} doesn't match output balance {}\n\
Inputs:\n\
\tIncoming validator rewards sum: {}\n\
\tInitial accounts balance sum: {}\n\
\tIncoming receipts balance sum: {}\n\
\tProcessed delayed receipts balance sum: {}\n\
\tInitial postponed receipts balance sum: {}\n\
Outputs:\n\
\tFinal accounts balance sum: {}\n\
\tOutgoing receipts balance sum: {}\n\
\tNew delayed receipts balance sum: {}\n\
\tFinal postponed receipts balance sum: {}\n\
\tTotal rent paid: {}\n\
\tTotal validators reward: {}\n\
\tTotal balance burnt: {}\n\
\tTotal balance slashed: {}",
InvalidAccessKeyError
Definition
pub enum InvalidAccessKeyError {
/// The access key identified by the `public_key` doesn't exist for the account
AccessKeyNotFound { account_id: AccountId, public_key: PublicKey },
/// Transaction `receiver_id` doesn't match the access key receiver_id
ReceiverMismatch { tx_receiver: AccountId, ak_receiver: AccountId },
/// Transaction method name isn't allowed by the access key
MethodNameMismatch { method_name: String },
/// Transaction requires a full permission access key.
RequiresFullAccess,
/// Access Key does not have enough allowance to cover transaction cost
NotEnoughAllowance {
account_id: AccountId,
public_key: PublicKey,
allowance: NearToken,
cost: NearToken,
},
/// Having a deposit with a function call action is not allowed with a function call access key.
DepositWithFunctionCall,
}
Error Messages
InvalidAccessKeyError::AccessKeyNotFound { account_id, public_key }
"Signer {:?} doesn't have access key with the given public_key {}"
InvalidAccessKeyError::ReceiverMismatch { tx_receiver, ak_receiver }
"Transaction receiver_id {:?} doesn't match the access key receiver_id {:?}"
InvalidAccessKeyError::MethodNameMismatch { method_name }
"Transaction method name {:?} isn't allowed by the access key"
InvalidAccessKeyError::RequiresFullAccess
"The transaction contains more then one action, but it was signed \
with an access key which allows transaction to apply only one specific action. \
To apply more then one actions TX must be signed with a full access key"
InvalidAccessKeyError::NotEnoughAllowance { account_id, public_key, allowance, cost }
"Access Key {:?}:{} does not have enough balance {} for transaction costing {}"
InvalidAccessKeyError::DepositWithFunctionCall
"Having a deposit with a function call action is not allowed with a function call access key."
ActionsValidationError
Definition
/// Describes the error for validating a list of actions.
pub enum ActionsValidationError {
/// The total prepaid gas (for all given actions) exceeded the limit.
TotalPrepaidGasExceeded { total_prepaid_gas: Gas, limit: Gas },
/// The number of actions exceeded the given limit.
TotalNumberOfActionsExceeded { total_number_of_actions: u64, limit: u64 },
/// The total number of bytes of the method names exceeded the limit in a Add Key action.
AddKeyMethodNamesNumberOfBytesExceeded { total_number_of_bytes: u64, limit: u64 },
/// The length of some method name exceeded the limit in a Add Key action.
AddKeyMethodNameLengthExceeded { length: u64, limit: u64 },
/// Integer overflow during a compute.
IntegerOverflow,
/// Invalid account ID.
InvalidAccountId { account_id: AccountId },
/// The size of the contract code exceeded the limit in a DeployContract action.
ContractSizeExceeded { size: u64, limit: u64 },
/// The length of the method name exceeded the limit in a Function Call action.
FunctionCallMethodNameLengthExceeded { length: u64, limit: u64 },
/// The length of the arguments exceeded the limit in a Function Call action.
FunctionCallArgumentsLengthExceeded { length: u64, limit: u64 },
}
Error Messages
ActionsValidationError::TotalPrepaidGasExceeded { total_prepaid_gas, limit }
"The total prepaid gas {} exceeds the limit {}"
ActionsValidationError::TotalNumberOfActionsExceeded {total_number_of_actions, limit }
"The total number of actions {} exceeds the limit {}"
ActionsValidationError::AddKeyMethodNamesNumberOfBytesExceeded { total_number_of_bytes, limit }
"The total number of bytes in allowed method names {} exceeds the maximum allowed number {} in a AddKey action"
ActionsValidationError::AddKeyMethodNameLengthExceeded { length, limit }
"The length of some method name {} exceeds the maximum allowed length {} in a AddKey action"
ActionsValidationError::IntegerOverflow
"Integer overflow during a compute"
ActionsValidationError::InvalidAccountId { account_id }
"Invalid account ID `{}`"
ActionsValidationError::ContractSizeExceeded { size, limit }
"The length of the contract size {} exceeds the maximum allowed size {} in a DeployContract action"
ActionsValidationError::FunctionCallMethodNameLengthExceeded { length, limit }
"The length of the method name {} exceeds the maximum allowed length {} in a FunctionCall action"
ActionsValidationError::FunctionCallArgumentsLengthExceeded { length, limit }
"The length of the arguments {} exceeds the maximum allowed length {} in a FunctionCall action"
TxExecutionError and subtypes
TxExecutionError
Definition
/// Error returned in the ExecutionOutcome in case of failure
pub enum TxExecutionError {
/// An error happened during Acton execution
ActionError(ActionError),
/// An error happened during Transaction execution
InvalidTxError(InvalidTxError),
}
ActionError
Definition
ActionError
pub struct ActionError {
/// Index of the failed action in the transaction.
/// Action index is not defined if ActionError.kind is `ActionErrorKind::RentUnpaid`
pub index: Option<u64>,
/// The kind of ActionError happened
pub kind: ActionErrorKind,
}
ActionErrorKind
Definition
pub enum ActionErrorKind {
/// Happens when CreateAccount action tries to create an account with account_id which is already exists in the storage
AccountAlreadyExists { account_id: AccountId },
/// Happens when TX receiver_id doesn't exist (but action is not Action::CreateAccount)
AccountDoesNotExist { account_id: AccountId },
/// A newly created account must be under a namespace of the creator account
CreateAccountNotAllowed { account_id: AccountId, predecessor_id: AccountId },
/// Administrative actions like `DeployContract`, `Stake`, `AddKey`, `DeleteKey`. can be proceed only if sender=receiver
/// or the first TX action is a `CreateAccount` action
ActorNoPermission { account_id: AccountId, actor_id: AccountId },
/// Account tries to remove an access key that doesn't exist
DeleteKeyDoesNotExist { account_id: AccountId, public_key: PublicKey },
/// The public key is already used for an existing access key
AddKeyAlreadyExists { account_id: AccountId, public_key: PublicKey },
/// Account is staking and can not be deleted
DeleteAccountStaking { account_id: AccountId },
/// Foreign sender (sender=!receiver) can delete an account only if a target account hasn't enough tokens to pay rent
DeleteAccountHasRent {
account_id: AccountId,
balance: NearToken,
},
/// ActionReceipt can't be completed, because the remaining balance will not be enough to pay rent.
RentUnpaid {
/// An account which is required to pay the rent
account_id: AccountId,
/// Rent due to pay.
amount: NearToken,
},
/// Account is not yet staked, but tries to unstake
TriesToUnstake { account_id: AccountId },
/// The account doesn't have enough balance to increase the stake.
TriesToStake {
account_id: AccountId,
stake: NearToken,
locked: NearToken,
balance: NearToken,
},
/// An error occurred during a `FunctionCall` Action.
FunctionCallError(FunctionCallError),
/// Error occurs when a new `ActionReceipt` created by the `FunctionCall` action fails
/// receipt validation.
NewReceiptValidationError(ReceiptValidationError),
}
Error Messages
ActionErrorKind::AccountAlreadyExists { account_id }
"Can't create a new account {:?}, because it already exists"
ActionErrorKind::AccountDoesNotExist { account_id }
"Can't complete the action because account {:?} doesn't exist"
ActionErrorKind::ActorNoPermission { actor_id, account_id }
"Actor {:?} doesn't have permission to account {:?} to complete the action"
ActionErrorKind::RentUnpaid { account_id, amount }
"The account {} wouldn't have enough balance to pay required rent {}"
ActionErrorKind::TriesToUnstake { account_id }
"Account {:?} is not yet staked, but tries to unstake"
ActionErrorKind::TriesToStake { account_id, stake, locked, balance }
"Account {:?} tries to stake {}, but has staked {} and only has {}"
ActionErrorKind::CreateAccountNotAllowed { account_id, predecessor_id }
"The new account_id {:?} can't be created by {:?}"
ActionErrorKind::DeleteKeyDoesNotExist { account_id, .. }
"Account {:?} tries to remove an access key that doesn't exist"
ActionErrorKind::AddKeyAlreadyExists { public_key, .. }
"The public key {:?} is already used for an existing access key"
ActionErrorKind::DeleteAccountStaking { account_id }
"Account {:?} is staking and can not be deleted"
ActionErrorKind::DeleteAccountHasRent { account_id, balance }
"Account {:?} can't be deleted. It has {}, which is enough to cover the rent"
ActionErrorKind::FunctionCallError(s)
ActionErrorKind::NewReceiptValidationError(e)
"An new action receipt created during a FunctionCall is not valid: {}"
ReceiptValidationError
Definition
/// Describes the error for validating a receipt.
pub enum ReceiptValidationError {
/// The `predecessor_id` of a Receipt is not valid.
InvalidPredecessorId { account_id: AccountId },
/// The `receiver_id` of a Receipt is not valid.
InvalidReceiverId { account_id: AccountId },
/// The `signer_id` of an ActionReceipt is not valid.
InvalidSignerId { account_id: AccountId },
/// The `receiver_id` of a DataReceiver within an ActionReceipt is not valid.
InvalidDataReceiverId { account_id: AccountId },
/// The length of the returned data exceeded the limit in a DataReceipt.
ReturnedValueLengthExceeded { length: u64, limit: u64 },
/// The number of input data dependencies exceeds the limit in an ActionReceipt.
NumberInputDataDependenciesExceeded { number_of_input_data_dependencies: u64, limit: u64 },
/// An error occurred while validating actions of an ActionReceipt.
ActionsValidation(ActionsValidationError),
/// Receipt is bigger than the limit.
/// ReceiptSizeExceeded means that there was a receipt above the size limit (currently 4MiB).
/// NEAR will refuse to execute receipts that are above the size limit.
/// The most likely source of such receipts would be cross-contract calls with a lot of large actions
/// (contract deployment, function call with large args, etc).
/// This error means that the user has to adjust their contract to generate smaller receipts.
ReceiptSizeExceeded { size: u64, limit: u64 },
}
Error Messages
ReceiptValidationError::InvalidPredecessorId { account_id }
"The predecessor_id `{}` of a Receipt is not valid."
ReceiptValidationError::InvalidReceiverId { account_id }
"The receiver_id `{}` of a Receipt is not valid."
ReceiptValidationError::InvalidSignerId { account_id }
"The signer_id `{}` of an ActionReceipt is not valid."
ReceiptValidationError::InvalidDataReceiverId { account_id }
"The receiver_id `{}` of a DataReceiver within an ActionReceipt is not valid."
ReceiptValidationError::ReturnedValueLengthExceeded { length, limit }
"The length of the returned data {} exceeded the limit {} in a DataReceipt"
ReceiptValidationError::NumberInputDataDependenciesExceeded { number_of_input_data_dependencies, limit }
"The number of input data dependencies {} exceeded the limit {} in an ActionReceipt"
ReceiptValidationError::ActionsValidation(e)
ReceiptValidationError::ReceiptSizeExceeded { size, limit }
"The size of the receipt exceeded the limit: {} > {}",
VMError and subtypes
VMError
Definition
pub enum VMError {
FunctionCallError(FunctionCallError),
/// Serialized external error from External trait implementation.
ExternalError(Vec<u8>),
/// An error that is caused by an operation on an inconsistent state.
/// E.g. an integer overflow by using a value from the given context.
InconsistentStateError(InconsistentStateError),
}
Error Messages
VMError::ExternalError
"Serialized ExternalError"
FunctionCallError
Definition
pub enum FunctionCallError {
CompilationError(CompilationError),
LinkError { msg: String },
MethodResolveError(MethodResolveError),
WasmTrap { msg: String },
HostError(HostError),
}
Error Messages
FunctionCallError::WasmTrap
"WebAssembly trap: {}"