Skip to main content

hopper_error

Attribute Macro hopper_error 

Source
#[hopper_error]
Expand description

Derive a Hopper error-code enum. Emits code(), variant_name(), From<T> for u32, and two const tables (CODE_TABLE, INVARIANT_TABLE) that the schema crate surfaces in the manifest.

Per-variant #[invariant = "name"] attributes are the innovation: when a runtime invariant check fails, the corresponding error carries the invariant name, and the off-chain SDK can render “Invariant x failed” instead of an opaque hex code.

§Example

#[hopper::error]
#[repr(u32)]
pub enum VaultError {
    #[invariant = "balance_nonzero"]
    InsufficientBalance = 0x1001,
    MigrationRequired,   // auto-assigned stable code
}