0x1::Errors
Module defining error codes used in Move aborts throughout the framework.
A u64
error code is constructed from two values:
The error category which is encoded in the lower 8 bits of the code. Error categories are declared in this module and are globally unique across the Diem framework. There is a limited fixed set of predefined categories, and the framework is guaranteed to use those consistently.
The error reason which is encoded in the remaining 56 bits of the code. The reason is a unique number relative to the module which raised the error and can be used to obtain more information about the error at hand. It is mostly used for diagnosis purposes. Error reasons may change over time as the framework evolves.
Rules to declare or use error reason:
make
invalid_state
requires_address
requires_role
requires_capability
not_published
already_published
invalid_argument
limit_exceeded
internal
deprecated
custom
Attempting to publish a resource that is already published. Example: calling an initialization function twice.
const ALREADY_PUBLISHED: u8 = 6;
A custom error category for extension points.
const CUSTOM: u8 = 255;
deprecated code
const DEPRECATED: u8 = 11;
An internal error (bug) has occurred.
const INTERNAL: u8 = 10;
An argument provided to an operation is invalid. Example: a signing key has the wrong format.
const INVALID_ARGUMENT: u8 = 7;
The system is in a state where the performed operation is not allowed. Example: call to a function only allowed in genesis
const INVALID_STATE: u8 = 1;
A limit on an amount, e.g. a currency, is exceeded. Example: withdrawal of money after account limits window is exhausted.
const LIMIT_EXCEEDED: u8 = 8;
A resource is required but not published. Example: access to non-existing resource.
const NOT_PUBLISHED: u8 = 5;
The signer of a transaction does not have the expected address for this operation. Example: a call to a function which publishes a resource under a particular address.
const REQUIRES_ADDRESS: u8 = 2;
The signer of a transaction does not have a required capability.
const REQUIRES_CAPABILITY: u8 = 4;
The signer of a transaction does not have the expected role for this operation. Example: a call to a function which requires the signer to have the role of treasury compliance.
const REQUIRES_ROLE: u8 = 3;
make
A function to create an error from from a category and a reason.
fun make(category: u8, reason: u64): u64
fun make(category: u8, reason: u64): u64 {
(category as u64) + (reason << 8)
}
pragma opaque = true;
pragma verify = false;
aborts_if [abstract] false;
ensures [abstract] result == category;
invalid_state
Create an error of invalid_state
public fun invalid_state(reason: u64): u64
public fun invalid_state(reason: u64): u64 { make(INVALID_STATE, reason) }
pragma opaque = true;
aborts_if false;
ensures result == INVALID_STATE;
requires_address
Create an error of requires_address
.
public fun requires_address(reason: u64): u64
public fun requires_address(reason: u64): u64 { make(REQUIRES_ADDRESS, reason) }
pragma opaque = true;
aborts_if false;
ensures result == REQUIRES_ADDRESS;
requires_role
Create an error of requires_role
.
public fun requires_role(reason: u64): u64
public fun requires_role(reason: u64): u64 { make(REQUIRES_ROLE, reason) }
pragma opaque = true;
aborts_if false;
ensures result == REQUIRES_ROLE;
requires_capability
Create an error of requires_capability
.
public fun requires_capability(reason: u64): u64
public fun requires_capability(reason: u64): u64 { make(REQUIRES_CAPABILITY, reason) }
pragma opaque = true;
aborts_if false;
ensures result == REQUIRES_CAPABILITY;
not_published
Create an error of not_published
.
public fun not_published(reason: u64): u64
public fun not_published(reason: u64): u64 { make(NOT_PUBLISHED, reason) }
pragma opaque = true;
aborts_if false;
ensures result == NOT_PUBLISHED;
already_published
Create an error of already_published
.
public fun already_published(reason: u64): u64
public fun already_published(reason: u64): u64 { make(ALREADY_PUBLISHED, reason) }
pragma opaque = true;
aborts_if false;
ensures result == ALREADY_PUBLISHED;
invalid_argument
Create an error of invalid_argument
.
public fun invalid_argument(reason: u64): u64
public fun invalid_argument(reason: u64): u64 { make(INVALID_ARGUMENT, reason) }
pragma opaque = true;
aborts_if false;
ensures result == INVALID_ARGUMENT;
limit_exceeded
Create an error of limit_exceeded
.
public fun limit_exceeded(reason: u64): u64
public fun limit_exceeded(reason: u64): u64 { make(LIMIT_EXCEEDED, reason) }
pragma opaque = true;
aborts_if false;
ensures result == LIMIT_EXCEEDED;
internal
Create an error of internal
.
public fun internal(reason: u64): u64
pragma opaque = true;
aborts_if false;
ensures result == INTERNAL;
deprecated
Create an error of deprecated
.
public fun deprecated(reason: u64): u64
public fun deprecated(reason: u64): u64 { make(DEPRECATED, reason) }
pragma opaque = true;
aborts_if false;
ensures result == DEPRECATED;
custom
Create an error of custom
.
public fun custom(reason: u64): u64
pragma opaque = true;
aborts_if false;
ensures result == CUSTOM;
pragma verify;
pragma aborts_if_is_strict;