【发布时间】:2022-06-16 14:08:51
【问题描述】:
我正在尝试在 solana 智能合约中编写错误枚举:
use anchor_lang::prelude::*;
#[error]
pub enum Errors {
#[msg("User cannot be created, missing data")]
CannotCreateUser,
#[msg("Cannot have more than 5 likes")]
ReachedMaxLikes,
}
我是这样用的
if image.likes == NUMBER_OF_ALLOWED_LIKES_SPACE {
return Err(Errors::ReachedMaxLikes.into());
}
我收到此错误
return Err(Errors::ReachedMaxLikes.into());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<Errors>` is not implemented for `anchor_lang::prelude::ProgramError`
|
我使用[ProgramError] 和#[derive(ProgramError)] 而不是[error],但错误消息仍然存在
【问题讨论】:
标签: rust blockchain smartcontracts solana