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 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 |
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
Optional data was unexpectedly None
.
Specified argument not provided.
Argument not of correct type.
Failed to deserialize a value.
casper_contract::storage::read()
returned an error.
The given key returned a None
value.
Failed to find a specified contract.
A call to casper_contract::runtime::get_key()
returned a failure.
The Key
variant was not as expected.
Obsolete error variant (we no longer have ContractRef).
Invalid purse name given.
Invalid purse retrieved.
Failed to upgrade contract at URef
.
Failed to transfer motes.
The given URef
has no access rights.
A given type could not be constructed from a CLValue
.
Early end of stream while deserializing.
Formatting error while deserializing.
Not all input bytes were consumed in deserialize
.
Out of memory error.
There are already MAX_ASSOCIATED_KEYS
AccountHash
s associated with the given account.
The given AccountHash
is already associated with the given
account.
Caller doesn’t have sufficient permissions to perform the given action.
The given AccountHash
is not associated with the given
account.
Removing/updating the given associated AccountHash
would
cause the total Weight
of all remaining AccountHash
s to
fall below one of the action thresholds for the given account.
Setting the key-management threshold to a value lower than the deployment threshold is disallowed.
Setting the deployment threshold to a value greater than any other threshold is disallowed.
Setting a threshold to a value greater than the total weight of associated keys is disallowed.
The given u32
doesn’t map to a SystemContractType
.
Failed to create a new purse.
An unhandled value, likely representing a bug in the code.
The provided buffer is too small to complete an operation.
No data available in the host buffer.
The host buffer has been set to a value and should be consumed first by a read operation.
Could not lay out an array in memory
The dictionary_item_key
length exceeds the maximum length.
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
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>,
R: 'a,
T: 'a,
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,
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
fn pipe_borrow<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Borrow<T>,
R: 'a,
T: 'a,
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,
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
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