Skip to main content

star_frame_error

Attribute Macro star_frame_error 

Source
#[star_frame_error]
Expand description

Derives the StarFrameError and ErrorsToIdl traits on an enum.

Additionally derives Copy, Clone, Debug, Display, Eq, and PartialEq.

§Attributes

§#[star_frame_error(offset = <u16>, skip_idl)] (item level attribute)

  • offset - The offset to use for the error code. Defaults to the first 2 bytes of the crate name’s sha256 hash. to avoid collisions from other crates. Each variant’s discriminant (even if explicitly set) will be offset by this value.
  • skip_idl - If present, ErrorsToIdl will not be derived.

§#[msg("My error message")] (required variant level attribute)

Used in the Display implementation and as the name for the IDL ErrorNode. The message must be a string literal.

§Example

use star_frame::prelude::*;

#[star_frame_error]
pub enum MyError {
    #[msg("An invalid argument was provided")]
    InvalidArgument2 = 0, // The actual error code will be offset by the crate name's sha256 hash
}