FunctionError

Derive Macro FunctionError 

Source
#[derive(FunctionError)]
Expand description

FunctionError generates implementation for near_sdk::FunctionError trait. It allows contract runtime to panic with the type using its ToString implementation as the message.

ยงExample

use near_sdk::{FunctionError, near};

#[derive(FunctionError)]
pub enum MyError {
    Error,
}

impl std::fmt::Display for MyError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            MyError::Error => write!(f, "Error"),
        }
    }
}

#[near(contract_state)]
pub struct Contract {}

#[near]
impl Contract {
    #[handle_result]
    pub fn some_function(&self) -> Result<(), MyError> {
        Err(MyError::Error)
    }
}