Enum casper_types::ApiError[][src]

pub enum ApiError {
Show 42 variants None, MissingArgument, InvalidArgument, Deserialize, Read, ValueNotFound, ContractNotFound, GetKey, UnexpectedKeyVariant, UnexpectedContractRefVariant, InvalidPurseName, InvalidPurse, UpgradeContractAtURef, Transfer, NoAccessRights, CLTypeMismatch, EarlyEndOfStream, Formatting, LeftOverBytes, OutOfMemory, MaxKeysLimit, DuplicateKey, PermissionDenied, MissingKey, ThresholdViolation, KeyManagementThreshold, DeploymentThreshold, InsufficientTotalWeight, InvalidSystemContract, PurseNotCreated, Unhandled, BufferTooSmall, HostBufferEmpty, HostBufferFull, AllocLayout, DictionaryItemKeyExceedsLength, InvalidDictionaryItemKey, AuctionError(u8), ContractHeader(u8), Mint(u8), HandlePayment(u8), User(u16),
}
Expand description

Errors which can be encountered while running a smart contract.

An ApiError can be converted to a u32 in order to be passed via the execution engine’s ext_ffi::casper_revert() function. This means the information each variant can convey is limited.

The variants are split into numeric ranges as follows:

Inclusive rangeVariant(s)
[1, 64511]all except reserved system contract error ranges defined below.
[64512, 64767]Auction
[64768, 65023]ContractHeader
[65024, 65279]Mint
[65280, 65535]HandlePayment
[65536, 131071]User

Mappings

The expanded mapping of all variants to their numerical equivalents is as follows:

// General system errors:
1 => None
2 => MissingArgument
3 => InvalidArgument
4 => Deserialize
5 => Read
6 => ValueNotFound
7 => ContractNotFound
8 => GetKey
9 => UnexpectedKeyVariant
10 => UnexpectedContractRefVariant
11 => InvalidPurseName
12 => InvalidPurse
13 => UpgradeContractAtURef
14 => Transfer
15 => NoAccessRights
16 => CLTypeMismatch
17 => EarlyEndOfStream
18 => Formatting
19 => LeftOverBytes
20 => OutOfMemory
21 => MaxKeysLimit
22 => DuplicateKey
23 => PermissionDenied
24 => MissingKey
25 => ThresholdViolation
26 => KeyManagementThreshold
27 => DeploymentThreshold
28 => InsufficientTotalWeight
29 => InvalidSystemContract
30 => PurseNotCreated
31 => Unhandled
32 => BufferTooSmall
33 => HostBufferEmpty
34 => HostBufferFull
// Auction errors:
use casper_types::system::auction::Error as AuctionError;
64_512 => AuctionError::MissingKey
64_513 => AuctionError::InvalidKeyVariant
64_514 => AuctionError::MissingValue
64_515 => AuctionError::Serialization
64_516 => AuctionError::TransferToBidPurse
64_517 => AuctionError::InvalidAmount
64_518 => AuctionError::BidNotFound
64_519 => AuctionError::ValidatorNotFound
64_520 => AuctionError::DelegatorNotFound
64_521 => AuctionError::Storage
64_522 => AuctionError::Bonding
64_523 => AuctionError::Unbonding
64_524 => AuctionError::ReleaseFounderStake
64_525 => AuctionError::GetBalance
64_526 => AuctionError::InvalidContext
64_527 => AuctionError::ValidatorFundsLocked
64_528 => AuctionError::InvalidCaller
64_529 => AuctionError::InvalidPublicKey
64_530 => AuctionError::BondNotFound
64_531 => AuctionError::CreatePurseFailed
64_532 => AuctionError::UnbondTooLarge
64_533 => AuctionError::BondTooSmall
64_534 => AuctionError::MissingDelegations
64_535 => AuctionError::MismatchedEraValidators
64_536 => AuctionError::MintReward
64_537 => AuctionError::InvalidValidatorSlotsValue
64_538 => AuctionError::MintReduceTotalSupply
64_539 => AuctionError::TransferToDelegatorPurse
64_540 => AuctionError::ValidatorRewardTransfer
64_541 => AuctionError::DelegatorRewardTransfer
64_542 => AuctionError::WithdrawDelegatorReward
64_543 => AuctionError::WithdrawValidatorReward
64_544 => AuctionError::TransferToUnbondingPurse
// Contract header errors:
use casper_types::contracts::Error as ContractHeaderError;
64_769 => ContractHeaderError::PreviouslyUsedVersion
64_770 => ContractHeaderError::ContractNotFound
64_771 => ContractHeaderError::GroupAlreadyExists
64_772 => ContractHeaderError::MaxGroupsExceeded
64_773 => ContractHeaderError::MaxTotalURefsExceeded
// Mint errors:
use casper_types::system::mint::Error as MintError;
65_024 => MintError::InsufficientFunds
65_025 => MintError::SourceNotFound
65_026 => MintError::DestNotFound
65_027 => MintError::InvalidURef
65_028 => MintError::InvalidAccessRights
65_029 => MintError::InvalidNonEmptyPurseCreation
65_030 => MintError::Storage
65_031 => MintError::PurseNotFound

// Handle Payment errors:
use casper_types::system::handle_payment::Error as PosError;
65_280 => PosError::NotBonded
65_281 => PosError::TooManyEventsInQueue
65_282 => PosError::CannotUnbondLastValidator
65_283 => PosError::SpreadTooHigh
65_284 => PosError::MultipleRequests
65_285 => PosError::BondTooSmall
65_286 => PosError::BondTooLarge
65_287 => PosError::UnbondTooLarge
65_288 => PosError::BondTransferFailed
65_289 => PosError::UnbondTransferFailed
65_290 => PosError::TimeWentBackwards
65_291 => PosError::StakesNotFound
65_292 => PosError::PaymentPurseNotFound
65_293 => PosError::PaymentPurseKeyUnexpectedType
65_294 => PosError::PaymentPurseBalanceNotFound
65_295 => PosError::BondingPurseNotFound
65_296 => PosError::BondingPurseKeyUnexpectedType
65_297 => PosError::RefundPurseKeyUnexpectedType
65_298 => PosError::RewardsPurseNotFound
65_299 => PosError::RewardsPurseKeyUnexpectedType
65_300 => PosError::StakesKeyDeserializationFailed
65_301 => PosError::StakesDeserializationFailed
65_302 => PosError::SystemFunctionCalledByUserAccount
65_303 => PosError::InsufficientPaymentForAmountSpent
65_304 => PosError::FailedTransferToRewardsPurse
65_305 => PosError::FailedTransferToAccountPurse
65_306 => PosError::SetRefundPurseCalledOutsidePayment

// User-defined errors:
65_536 => User(0)
65_537 => User(1)
65_538 => User(2)
131_071 => User(u16::max_value())

Users can specify a C-style enum and implement From to ease usage of casper_contract::runtime::revert(), e.g.

use casper_types::ApiError;

#[repr(u16)]
enum FailureCode {
    Zero = 0,  // 65,536 as an ApiError::User
    One,       // 65,537 as an ApiError::User
    Two        // 65,538 as an ApiError::User
}

impl From<FailureCode> for ApiError {
    fn from(code: FailureCode) -> Self {
        ApiError::User(code as u16)
    }
}

assert_eq!(ApiError::User(1), FailureCode::One.into());
assert_eq!(65_536, u32::from(ApiError::from(FailureCode::Zero)));
assert_eq!(65_538, u32::from(ApiError::from(FailureCode::Two)));

Variants

None

Optional data was unexpectedly None.

MissingArgument

Specified argument not provided.

InvalidArgument

Argument not of correct type.

Deserialize

Failed to deserialize a value.

Read

casper_contract::storage::read() returned an error.

ValueNotFound

The given key returned a None value.

ContractNotFound

Failed to find a specified contract.

GetKey

A call to casper_contract::runtime::get_key() returned a failure.

UnexpectedKeyVariant

The Key variant was not as expected.

UnexpectedContractRefVariant

Obsolete error variant (we no longer have ContractRef).

InvalidPurseName

Invalid purse name given.

InvalidPurse

Invalid purse retrieved.

UpgradeContractAtURef

Failed to upgrade contract at URef.

Transfer

Failed to transfer motes.

NoAccessRights

The given URef has no access rights.

CLTypeMismatch

A given type could not be constructed from a CLValue.

EarlyEndOfStream

Early end of stream while deserializing.

Formatting

Formatting error while deserializing.

LeftOverBytes

Not all input bytes were consumed in deserialize.

OutOfMemory

Out of memory error.

MaxKeysLimit

There are already MAX_ASSOCIATED_KEYS AccountHashs associated with the given account.

DuplicateKey

The given AccountHash is already associated with the given account.

PermissionDenied

Caller doesn’t have sufficient permissions to perform the given action.

MissingKey

The given AccountHash is not associated with the given account.

ThresholdViolation

Removing/updating the given associated AccountHash would cause the total Weight of all remaining AccountHashs to fall below one of the action thresholds for the given account.

KeyManagementThreshold

Setting the key-management threshold to a value lower than the deployment threshold is disallowed.

DeploymentThreshold

Setting the deployment threshold to a value greater than any other threshold is disallowed.

InsufficientTotalWeight

Setting a threshold to a value greater than the total weight of associated keys is disallowed.

InvalidSystemContract

The given u32 doesn’t map to a SystemContractType.

PurseNotCreated

Failed to create a new purse.

Unhandled

An unhandled value, likely representing a bug in the code.

BufferTooSmall

The provided buffer is too small to complete an operation.

HostBufferEmpty

No data available in the host buffer.

HostBufferFull

The host buffer has been set to a value and should be consumed first by a read operation.

AllocLayout

Could not lay out an array in memory

DictionaryItemKeyExceedsLength

The dictionary_item_key length exceeds the maximum length.

InvalidDictionaryItemKey

The dictionary_item_key is invalid.

AuctionError(u8)

Error specific to Auction contract.

Tuple Fields of AuctionError

0: u8
ContractHeader(u8)

Contract header errors.

Tuple Fields of ContractHeader

0: u8
Mint(u8)

Error specific to Mint contract.

Tuple Fields of Mint

0: u8
HandlePayment(u8)

Error specific to Handle Payment contract.

Tuple Fields of HandlePayment

0: u8
User(u16)

User-specified error code. The internal u16 value is added to u16::MAX as u32 + 1 when an Error::User is converted to a u32.

Tuple Fields of User

0: u16

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts self into a target type. Read more

Causes self to use its Binary implementation when Debug-formatted.

Causes self to use its Display implementation when Debug-formatted. Read more

Causes self to use its LowerExp implementation when Debug-formatted. Read more

Causes self to use its LowerHex implementation when Debug-formatted. Read more

Causes self to use its Octal implementation when Debug-formatted.

Causes self to use its Pointer implementation when Debug-formatted. Read more

Causes self to use its UpperExp implementation when Debug-formatted. Read more

Causes self to use its UpperHex implementation when Debug-formatted. Read more

Performs the conversion.

Performs the conversion.

Pipes a value into a function that cannot ordinarily be called in suffix position. Read more

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

Pipes a dereference into a function that cannot normally be called in suffix position. Read more

Pipes a mutable dereference into a function that cannot normally be called in suffix position. Read more

Pipes a reference into a function that cannot ordinarily be called in suffix position. Read more

Pipes a mutable reference into a function that cannot ordinarily be called in suffix position. Read more

Should always be Self

Provides immutable access for inspection. Read more

Calls tap in debug builds, and does nothing in release builds.

Provides mutable access for modification. Read more

Calls tap_mut in debug builds, and does nothing in release builds.

Provides immutable access to the reference for inspection.

Calls tap_ref in debug builds, and does nothing in release builds.

Provides mutable access to the reference for modification.

Calls tap_ref_mut in debug builds, and does nothing in release builds.

Provides immutable access to the borrow for inspection. Read more

Calls tap_borrow in debug builds, and does nothing in release builds.

Provides mutable access to the borrow for modification.

Calls tap_borrow_mut in debug builds, and does nothing in release builds. Read more

Immutably dereferences self for inspection.

Calls tap_deref in debug builds, and does nothing in release builds.

Mutably dereferences self for modification.

Calls tap_deref_mut in debug builds, and does nothing in release builds. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

Attempts to convert self into a target type. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.