Enum casper_types::ApiError [−][src]
pub enum ApiError {
Show 43 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,
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 range | Variant(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
Optional data was unexpectedly None.
assert_eq!(ApiError::from(1), ApiError::None);Specified argument not provided.
assert_eq!(ApiError::from(2), ApiError::MissingArgument);Argument not of correct type.
assert_eq!(ApiError::from(3), ApiError::InvalidArgument);Failed to deserialize a value.
assert_eq!(ApiError::from(4), ApiError::Deserialize);casper_contract::storage::read() returned an error.
assert_eq!(ApiError::from(5), ApiError::Read);The given key returned a None value.
assert_eq!(ApiError::from(6), ApiError::ValueNotFound);Failed to find a specified contract.
assert_eq!(ApiError::from(7), ApiError::ContractNotFound);A call to casper_contract::runtime::get_key() returned a failure.
assert_eq!(ApiError::from(8), ApiError::GetKey);The Key variant was not as expected.
assert_eq!(ApiError::from(9), ApiError::UnexpectedKeyVariant);Obsolete error variant (we no longer have ContractRef).
assert_eq!(ApiError::from(10), ApiError::UnexpectedContractRefVariant);Invalid purse name given.
assert_eq!(ApiError::from(11), ApiError::InvalidPurseName);Invalid purse retrieved.
assert_eq!(ApiError::from(12), ApiError::InvalidPurse);Failed to upgrade contract at URef.
assert_eq!(ApiError::from(13), ApiError::UpgradeContractAtURef);Failed to transfer motes.
assert_eq!(ApiError::from(14), ApiError::Transfer);The given URef has no access rights.
assert_eq!(ApiError::from(15), ApiError::NoAccessRights);A given type could not be constructed from a CLValue.
assert_eq!(ApiError::from(16), ApiError::CLTypeMismatch);Early end of stream while deserializing.
assert_eq!(ApiError::from(17), ApiError::EarlyEndOfStream);Formatting error while deserializing.
assert_eq!(ApiError::from(18), ApiError::Formatting);Not all input bytes were consumed in deserialize.
assert_eq!(ApiError::from(19), ApiError::LeftOverBytes);Out of memory error.
assert_eq!(ApiError::from(20), ApiError::OutOfMemory);There are already maximum AccountHashs associated with the
given account.
assert_eq!(ApiError::from(21), ApiError::MaxKeysLimit);The given AccountHash is already associated with the given
account.
assert_eq!(ApiError::from(22), ApiError::DuplicateKey);Caller doesn’t have sufficient permissions to perform the given action.
assert_eq!(ApiError::from(23), ApiError::PermissionDenied);The given AccountHash is not associated with the given
account.
assert_eq!(ApiError::from(24), ApiError::MissingKey);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);Setting the key-management threshold to a value lower than the deployment threshold is disallowed.
assert_eq!(ApiError::from(26), ApiError::KeyManagementThreshold);Setting the deployment threshold to a value greater than any other threshold is disallowed.
assert_eq!(ApiError::from(27), ApiError::DeploymentThreshold);Setting a threshold to a value greater than the total weight of associated keys is disallowed.
assert_eq!(ApiError::from(28), ApiError::InsufficientTotalWeight);The given u32 doesn’t map to a SystemContractType.
assert_eq!(ApiError::from(29), ApiError::InvalidSystemContract);Failed to create a new purse.
assert_eq!(ApiError::from(30), ApiError::PurseNotCreated);An unhandled value, likely representing a bug in the code.
assert_eq!(ApiError::from(31), ApiError::Unhandled);The provided buffer is too small to complete an operation.
assert_eq!(ApiError::from(32), ApiError::BufferTooSmall);No data available in the host buffer.
assert_eq!(ApiError::from(33), ApiError::HostBufferEmpty);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);Could not lay out an array in memory
assert_eq!(ApiError::from(35), ApiError::AllocLayout);The dictionary_item_key length exceeds the maximum length.
assert_eq!(ApiError::from(36), ApiError::DictionaryItemKeyExceedsLength);The dictionary_item_key is invalid.
assert_eq!(ApiError::from(37), ApiError::InvalidDictionaryItemKey);Unable to retrieve the requested system contract hash.
assert_eq!(ApiError::from(38), ApiError::MissingSystemContractHash);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)));
}Tuple Fields of AuctionError
0: u8ContractHeader(u8)Contract header errors. See casper_types::contracts::Error.
for code in 64768..=65023 {
assert!(matches!(ApiError::from(code), ApiError::ContractHeader(_contract_header_error)));
}Tuple Fields of ContractHeader
0: u8Mint(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)));
}Tuple Fields of Mint
0: u8HandlePayment(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)));
}Tuple Fields of HandlePayment
0: u8User(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(_)));
}Tuple Fields of User
0: u16Trait Implementations
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Auto Trait Implementations
impl RefUnwindSafe for ApiError
impl UnwindSafe for ApiError
Blanket Implementations
Mutably borrows from an owned value. Read more
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
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,
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,
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,
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
Causes self to use its LowerHex implementation when
Debug-formatted. Read more
Causes self to use its Octal implementation when Debug-formatted.
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
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,
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,
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
Causes self to use its UpperHex implementation when
Debug-formatted. Read more
fn pipe_as_ref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: AsRef<T>,
T: 'a,
R: 'a,
fn pipe_as_ref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: AsRef<T>,
T: 'a,
R: '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>,
T: 'a,
R: 'a,
fn pipe_as_mut<'a, T, R>(&'a mut self, func: impl FnOnce(&'a mut T) -> R) -> R where
Self: AsMut<T>,
T: 'a,
R: 'a,
Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more
fn pipe_borrow<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Borrow<T>,
T: 'a,
R: 'a,
fn pipe_borrow<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Borrow<T>,
T: 'a,
R: '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>,
T: 'a,
R: 'a,
fn pipe_borrow_mut<'a, T, R>(
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
Self: BorrowMut<T>,
T: 'a,
R: 'a,
Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more
fn pipe_deref<'a, R>(&'a self, func: impl FnOnce(&'a Self::Target) -> R) -> R where
Self: Deref,
R: 'a,
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,
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
Pipes a reference into a function that cannot ordinarily be called in suffix position. Read more
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
fn tap_mut_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&mut Self) -> R,
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,
impl<T, U> TapAsRef<U> for T where
U: ?Sized,
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,
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,
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,
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,
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,
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,
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,
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,
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
Immutably dereferences self for inspection.
fn tap_deref_dbg<F, R>(self, func: F) -> Self where
Self: Deref,
F: FnOnce(&Self::Target) -> R,
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,
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,
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