[][src]Enum casperlabs_types::ApiError

pub enum ApiError {
    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,
    ContractHeader(u8),
    Mint(u8),
    ProofOfStake(u8),
    User(u16),
}

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::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, 65023]all except Mint, ProofOfStake and User
[65024, 65279]Mint
[65280, 65535]ProofOfStake
[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
// Contract header errors:
use casperlabs_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 casperlabs_types::system_contract_errors::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

// Proof of stake errors:
use casperlabs_types::system_contract_errors::pos::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 casperlabs_contract::runtime::revert(), e.g.

use casperlabs_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

casperlabs_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 casperlabs_contract::runtime::get_key() returned a failure.

UnexpectedKeyVariant

The Key variant was not as expected.

UnexpectedContractRefVariant

The ContractRef variant was not as expected.

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

ContractHeader(u8)

Contract header errors.

Mint(u8)

Error specific to Mint contract.

ProofOfStake(u8)

Error specific to Proof of Stake contract.

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.

Trait Implementations

impl Clone for ApiError[src]

impl Copy for ApiError[src]

impl Debug for ApiError[src]

impl Display for ApiError[src]

impl Eq for ApiError[src]

impl From<AddKeyFailure> for ApiError[src]

impl From<ApiError> for u32[src]

impl From<CLValueError> for ApiError[src]

impl From<Error> for ApiError[src]

impl From<Error> for ApiError[src]

impl From<Error> for ApiError[src]

impl From<Error> for ApiError[src]

impl From<RemoveKeyFailure> for ApiError[src]

impl From<SetThresholdFailure> for ApiError[src]

impl From<TryFromSliceForAccountHashError> for ApiError[src]

impl From<UpdateKeyFailure> for ApiError[src]

impl From<u32> for ApiError[src]

impl PartialEq<ApiError> for ApiError[src]

impl StructuralEq for ApiError[src]

impl StructuralPartialEq for ApiError[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.