Enum casper_types::ApiError

source ·
#[non_exhaustive]
pub enum ApiError {
Show 45 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, MissingSystemContractHash, ExceededRecursionDepth, NonRepresentableSerialization, 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

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 (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

None

Optional data was unexpectedly None.

assert_eq!(ApiError::from(1), ApiError::None);
§

MissingArgument

Specified argument not provided.

assert_eq!(ApiError::from(2), ApiError::MissingArgument);
§

InvalidArgument

Argument not of correct type.

assert_eq!(ApiError::from(3), ApiError::InvalidArgument);
§

Deserialize

Failed to deserialize a value.

assert_eq!(ApiError::from(4), ApiError::Deserialize);
§

Read

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

assert_eq!(ApiError::from(5), ApiError::Read);
§

ValueNotFound

The given key returned a None value.

assert_eq!(ApiError::from(6), ApiError::ValueNotFound);
§

ContractNotFound

Failed to find a specified contract.

assert_eq!(ApiError::from(7), ApiError::ContractNotFound);
§

GetKey

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

assert_eq!(ApiError::from(8), ApiError::GetKey);
§

UnexpectedKeyVariant

The Key variant was not as expected.

assert_eq!(ApiError::from(9), ApiError::UnexpectedKeyVariant);
§

UnexpectedContractRefVariant

Obsolete error variant (we no longer have ContractRef).

assert_eq!(ApiError::from(10), ApiError::UnexpectedContractRefVariant);
§

InvalidPurseName

Invalid purse name given.

assert_eq!(ApiError::from(11), ApiError::InvalidPurseName);
§

InvalidPurse

Invalid purse retrieved.

assert_eq!(ApiError::from(12), ApiError::InvalidPurse);
§

UpgradeContractAtURef

Failed to upgrade contract at URef.

assert_eq!(ApiError::from(13), ApiError::UpgradeContractAtURef);
§

Transfer

Failed to transfer motes.

assert_eq!(ApiError::from(14), ApiError::Transfer);
§

NoAccessRights

The given URef has no access rights.

assert_eq!(ApiError::from(15), ApiError::NoAccessRights);
§

CLTypeMismatch

A given type could not be constructed from a CLValue.

assert_eq!(ApiError::from(16), ApiError::CLTypeMismatch);
§

EarlyEndOfStream

Early end of stream while deserializing.

assert_eq!(ApiError::from(17), ApiError::EarlyEndOfStream);
§

Formatting

Formatting error while deserializing.

assert_eq!(ApiError::from(18), ApiError::Formatting);
§

LeftOverBytes

Not all input bytes were consumed in deserialize.

assert_eq!(ApiError::from(19), ApiError::LeftOverBytes);
§

OutOfMemory

Out of memory error.

assert_eq!(ApiError::from(20), ApiError::OutOfMemory);
§

MaxKeysLimit

There are already maximum AccountHashs associated with the given account.

assert_eq!(ApiError::from(21), ApiError::MaxKeysLimit);
§

DuplicateKey

The given AccountHash is already associated with the given account.

assert_eq!(ApiError::from(22), ApiError::DuplicateKey);
§

PermissionDenied

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

assert_eq!(ApiError::from(23), ApiError::PermissionDenied);
§

MissingKey

The given AccountHash is not associated with the given account.

assert_eq!(ApiError::from(24), ApiError::MissingKey);
§

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.

assert_eq!(ApiError::from(25), ApiError::ThresholdViolation);
§

KeyManagementThreshold

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

assert_eq!(ApiError::from(26), ApiError::KeyManagementThreshold);
§

DeploymentThreshold

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

assert_eq!(ApiError::from(27), ApiError::DeploymentThreshold);
§

InsufficientTotalWeight

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

assert_eq!(ApiError::from(28), ApiError::InsufficientTotalWeight);
§

InvalidSystemContract

The given u32 doesn’t map to a SystemContractType.

assert_eq!(ApiError::from(29), ApiError::InvalidSystemContract);
§

PurseNotCreated

Failed to create a new purse.

assert_eq!(ApiError::from(30), ApiError::PurseNotCreated);
§

Unhandled

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

assert_eq!(ApiError::from(31), ApiError::Unhandled);
§

BufferTooSmall

The provided buffer is too small to complete an operation.

assert_eq!(ApiError::from(32), ApiError::BufferTooSmall);
§

HostBufferEmpty

No data available in the host buffer.

assert_eq!(ApiError::from(33), ApiError::HostBufferEmpty);
§

HostBufferFull

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

assert_eq!(ApiError::from(34), ApiError::HostBufferFull);
§

AllocLayout

Could not lay out an array in memory

assert_eq!(ApiError::from(35), ApiError::AllocLayout);
§

DictionaryItemKeyExceedsLength

The dictionary_item_key length exceeds the maximum length.

assert_eq!(ApiError::from(36), ApiError::DictionaryItemKeyExceedsLength);
§

InvalidDictionaryItemKey

The dictionary_item_key is invalid.

assert_eq!(ApiError::from(37), ApiError::InvalidDictionaryItemKey);
§

MissingSystemContractHash

Unable to retrieve the requested system contract hash.

assert_eq!(ApiError::from(38), ApiError::MissingSystemContractHash);
§

ExceededRecursionDepth

Exceeded a recursion depth limit.

assert_eq!(ApiError::from(39), ApiError::ExceededRecursionDepth);
§

NonRepresentableSerialization

Attempt to serialize a value that does not have a serialized representation.

assert_eq!(ApiError::from(40), ApiError::NonRepresentableSerialization);
§

AuctionError(u8)

Error specific to Auction contract. See casper_types::system::auction::Error.

for code in 64512..=64767 {
    assert!(matches!(ApiError::from(code), ApiError::AuctionError(_auction_error)));
}
§

ContractHeader(u8)

Contract header errors. See casper_types::contracts::Error.

for code in 64768..=65023 {
    assert!(matches!(ApiError::from(code), ApiError::ContractHeader(_contract_header_error)));
}
§

Mint(u8)

Error specific to Mint contract. See casper_types::system::mint::Error.

for code in 65024..=65279 {
    assert!(matches!(ApiError::from(code), ApiError::Mint(_mint_error)));
}
§

HandlePayment(u8)

Error specific to Handle Payment contract. See casper_types::system::handle_payment.

for code in 65280..=65535 {
    assert!(matches!(ApiError::from(code), ApiError::HandlePayment(_handle_payment_error)));
}
§

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.

for code in 65536..131071 {
    assert!(matches!(ApiError::from(code), ApiError::User(_)));
}

Trait Implementations§

source§

impl Clone for ApiError

source§

fn clone(&self) -> ApiError

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ApiError

source§

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

Formats the value using the given formatter. Read more
source§

impl Display for ApiError

source§

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

Formats the value using the given formatter. Read more
source§

impl From<AddKeyFailure> for ApiError

source§

fn from(error: AddKeyFailure) -> Self

Converts to this type from the input type.
source§

impl From<ApiError> for u32

source§

fn from(error: ApiError) -> Self

Converts to this type from the input type.
source§

impl From<CLValueError> for ApiError

source§

fn from(error: CLValueError) -> Self

Converts to this type from the input type.
source§

impl From<Error> for ApiError

source§

fn from(error: Error) -> Self

Converts to this type from the input type.
source§

impl From<Error> for ApiError

source§

fn from(error: Error) -> Self

Converts to this type from the input type.
source§

impl From<Error> for ApiError

source§

fn from(error: Error) -> Self

Converts to this type from the input type.
source§

impl From<Error> for ApiError

source§

fn from(error: Error) -> Self

Converts to this type from the input type.
source§

impl From<Error> for ApiError

source§

fn from(error: Error) -> Self

Converts to this type from the input type.
source§

impl From<RemoveKeyFailure> for ApiError

source§

fn from(error: RemoveKeyFailure) -> Self

Converts to this type from the input type.
source§

impl From<SetThresholdFailure> for ApiError

source§

fn from(error: SetThresholdFailure) -> Self

Converts to this type from the input type.
source§

impl From<TryFromSliceForAccountHashError> for ApiError

source§

fn from(_error: TryFromSliceForAccountHashError) -> Self

Converts to this type from the input type.
source§

impl From<UpdateKeyFailure> for ApiError

source§

fn from(error: UpdateKeyFailure) -> Self

Converts to this type from the input type.
source§

impl From<u32> for ApiError

source§

fn from(value: u32) -> ApiError

Converts to this type from the input type.
source§

impl PartialEq for ApiError

source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for ApiError

source§

impl Eq for ApiError

source§

impl StructuralPartialEq for ApiError

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.