Enum casper_types::ApiError[][src]

pub enum ApiError {
Show 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, 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

AuctionError(u8)

Error specific to Auction contract.

ContractHeader(u8)

Contract header errors.

Mint(u8)

Error specific to Mint contract.

HandlePayment(u8)

Error specific to Handle Payment 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]

fn clone(&self) -> ApiError[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for ApiError[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl Display for ApiError[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl From<AddKeyFailure> for ApiError[src]

fn from(error: AddKeyFailure) -> Self[src]

Performs the conversion.

impl From<CLValueError> for ApiError[src]

fn from(error: CLValueError) -> Self[src]

Performs the conversion.

impl From<Error> for ApiError[src]

fn from(error: Error) -> Self[src]

Performs the conversion.

impl From<Error> for ApiError[src]

fn from(error: Error) -> Self[src]

Performs the conversion.

impl From<Error> for ApiError[src]

fn from(error: Error) -> Self[src]

Performs the conversion.

impl From<Error> for ApiError[src]

fn from(error: Error) -> Self[src]

Performs the conversion.

impl From<Error> for ApiError[src]

fn from(error: Error) -> Self[src]

Performs the conversion.

impl From<RemoveKeyFailure> for ApiError[src]

fn from(error: RemoveKeyFailure) -> Self[src]

Performs the conversion.

impl From<SetThresholdFailure> for ApiError[src]

fn from(error: SetThresholdFailure) -> Self[src]

Performs the conversion.

impl From<TryFromSliceForAccountHashError> for ApiError[src]

fn from(_error: TryFromSliceForAccountHashError) -> Self[src]

Performs the conversion.

impl From<UpdateKeyFailure> for ApiError[src]

fn from(error: UpdateKeyFailure) -> Self[src]

Performs the conversion.

impl From<u32> for ApiError[src]

fn from(value: u32) -> ApiError[src]

Performs the conversion.

impl PartialEq<ApiError> for ApiError[src]

fn eq(&self, other: &ApiError) -> bool[src]

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

fn ne(&self, other: &ApiError) -> bool[src]

This method tests for !=.

impl Copy for ApiError[src]

impl Eq 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]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> Conv for T

fn conv<T>(self) -> T where
    Self: Into<T>, 

Converts self into a target type. Read more

impl<T> FmtForward for T

fn fmt_binary(self) -> FmtBinary<Self> where
    Self: Binary

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

fn fmt_display(self) -> FmtDisplay<Self> where
    Self: Display

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

fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
    Self: LowerExp

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

fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
    Self: LowerHex

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

fn fmt_octal(self) -> FmtOctal<Self> where
    Self: Octal

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

fn fmt_pointer(self) -> FmtPointer<Self> where
    Self: Pointer

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

fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
    Self: UpperExp

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

fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
    Self: UpperHex

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

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Pipe for T

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R

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

impl<T> PipeAsRef for T

fn pipe_as_ref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
    Self: AsRef<T>,
    R: 'a,
    T: 'a, 

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

fn pipe_as_mut<'a, T, R>(&'a mut self, func: impl FnOnce(&'a mut T) -> R) -> R where
    Self: AsMut<T>,
    R: 'a,
    T: 'a, 

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

impl<T> PipeBorrow for T

fn pipe_borrow<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
    Self: Borrow<T>,
    R: 'a,
    T: 'a, 

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

fn pipe_borrow_mut<'a, T, R>(
    &'a mut self,
    func: impl FnOnce(&'a mut T) -> R
) -> R where
    Self: BorrowMut<T>,
    R: 'a,
    T: 'a, 

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

impl<T> PipeDeref for T

fn pipe_deref<'a, R>(&'a self, func: impl FnOnce(&'a Self::Target) -> R) -> R where
    Self: Deref,
    R: 'a, 

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

fn pipe_deref_mut<'a, R>(
    &'a mut self,
    func: impl FnOnce(&'a mut Self::Target) -> R
) -> R where
    Self: DerefMut,
    R: 'a, 

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

impl<T> PipeRef for T

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R where
    R: 'a, 

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

fn pipe_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
    R: 'a, 

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

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Tap for T

fn tap<F, R>(self, func: F) -> Self where
    F: FnOnce(&Self) -> R, 

Provides immutable access for inspection. Read more

fn tap_dbg<F, R>(self, func: F) -> Self where
    F: FnOnce(&Self) -> R, 

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

fn tap_mut<F, R>(self, func: F) -> Self where
    F: FnOnce(&mut Self) -> R, 

Provides mutable access for modification. Read more

fn tap_mut_dbg<F, R>(self, func: F) -> Self where
    F: FnOnce(&mut Self) -> R, 

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

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

fn tap_ref<F, R>(self, func: F) -> Self where
    Self: AsRef<T>,
    F: FnOnce(&T) -> R, 

Provides immutable access to the reference for inspection.

fn tap_ref_dbg<F, R>(self, func: F) -> Self where
    Self: AsRef<T>,
    F: FnOnce(&T) -> R, 

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

fn tap_ref_mut<F, R>(self, func: F) -> Self where
    Self: AsMut<T>,
    F: FnOnce(&mut T) -> R, 

Provides mutable access to the reference for modification.

fn tap_ref_mut_dbg<F, R>(self, func: F) -> Self where
    Self: AsMut<T>,
    F: FnOnce(&mut T) -> R, 

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

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

fn tap_borrow<F, R>(self, func: F) -> Self where
    Self: Borrow<T>,
    F: FnOnce(&T) -> R, 

Provides immutable access to the borrow for inspection. Read more

fn tap_borrow_dbg<F, R>(self, func: F) -> Self where
    Self: Borrow<T>,
    F: FnOnce(&T) -> R, 

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

fn tap_borrow_mut<F, R>(self, func: F) -> Self where
    Self: BorrowMut<T>,
    F: FnOnce(&mut T) -> R, 

Provides mutable access to the borrow for modification.

fn tap_borrow_mut_dbg<F, R>(self, func: F) -> Self where
    Self: BorrowMut<T>,
    F: FnOnce(&mut T) -> R, 

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

impl<T> TapDeref for T

fn tap_deref<F, R>(self, func: F) -> Self where
    Self: Deref,
    F: FnOnce(&Self::Target) -> R, 

Immutably dereferences self for inspection.

fn tap_deref_dbg<F, R>(self, func: F) -> Self where
    Self: Deref,
    F: FnOnce(&Self::Target) -> R, 

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

fn tap_deref_mut<F, R>(self, func: F) -> Self where
    Self: DerefMut,
    F: FnOnce(&mut Self::Target) -> R, 

Mutably dereferences self for modification.

fn tap_deref_mut_dbg<F, R>(self, func: F) -> Self where
    Self: DerefMut,
    F: FnOnce(&mut Self::Target) -> R, 

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

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

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

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

recently added

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

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

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T> TryConv for T

fn try_conv<T>(self) -> Result<T, Self::Error> where
    Self: TryInto<T>, 

Attempts to convert self into a target type. Read more

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V