这里导入了 error,但它是一个类似函数的宏



我已经创建了一个宏来处理所有错误,然后将在代码中单独实现。但是我得到一些错误。

#[error]
pub enum ErrorCode {
#[msg("SOMETHING 1")]
Unauthorized,
}

并实现它们,例如:-

if a != b {
return Err(ErrorCode::Unauthorized.into());
}

现在错误是

error: cannot find attribute `error` in this scope
--> programs/xxx/src/lib.rs:287:3
|
287 | #[error]
|   ^^^^^
|
note: `error` is imported here, but it is a function-like macro
--> programs/xxx/src/lib.rs:1:5
|
1   | use anchor_lang::prelude::*;
|     ^^^^^^^^^^^^^^^^^^^^^^^
error: cannot find attribute `msg` in this scope
--> programs/xxx/src/lib.rs:289:7
|
289 |     #[msg("You are not authorized to complete this transaction")]
|       ^^^
|
note: `msg` is imported here, but it is a function-like macro
--> programs/xxx/src/lib.rs:1:5
|
1   | use anchor_lang::prelude::*;
|     ^^^^^^^^^^^^^^^^^^^^^^^
error[E0599]: no variant or associated item named `Unauthorized` found for enum `anchor_lang::error::ErrorCode` in the current scope
--> programs/xxx/src/lib.rs:132:39
|
132 |                 return Err(ErrorCode::Unauthorized.Into());
|                                       ^^^^^^^^^^^^ variant or associated item not found in `anchor_lang::error::ErrorCode`

您需要使用[error_code]宏而不是[error],我认为这是在更新期间所做的更改。

相关内容

  • 没有找到相关文章

最新更新