lang: adjust error code so `#[error_code]` works with just importing `anchor_lang::error_code` (#1610)

This commit is contained in:
Paul 2022-03-16 14:53:43 -04:00 committed by GitHub
parent b376fd4615
commit 170a763625
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 11 deletions

View File

@ -29,6 +29,7 @@ incremented for features.
* spl: Update `spl/governance` to use new errors ([#1582](https://github.com/project-serum/anchor/pull/1582)).
* client: Fix `Cluster`'s `FromStr` implementation ([#1362](https://github.com/project-serum/anchor/pull/1362)).
* lang: implement `Key` for `Pubkey` again, so `associated_token::*` constraints can use pubkey targets again ([#1601](https://github.com/project-serum/anchor/pull/1601)).
* lang: adjust error code so `#[error_code]` works with just importing `anchor_lang::error_code` ([#1610](https://github.com/project-serum/anchor/pull/1610)).
* cli/ts: generated `IDL` variable in `types/<project-name.ts>` should equal the `<project-name>.json` idl file ([#1609](https://github.com/project-serum/anchor/pull/1609))
### Breaking

View File

@ -1,4 +1,4 @@
use anchor_attribute_error::error_code;
use anchor_lang::error_code;
use borsh::maybestd::io::Error as BorshIoError;
use solana_program::{program_error::ProgramError, pubkey::Pubkey};
use std::fmt::{Debug, Display};

View File

@ -48,7 +48,7 @@ pub use crate::bpf_upgradeable_state::*;
pub use anchor_attribute_access_control::access_control;
pub use anchor_attribute_account::{account, declare_id, zero_copy};
pub use anchor_attribute_constant::constant;
pub use anchor_attribute_error;
pub use anchor_attribute_error::*;
pub use anchor_attribute_event::{emit, event};
pub use anchor_attribute_interface::interface;
pub use anchor_attribute_program::program;
@ -355,14 +355,12 @@ pub mod __private {
macro_rules! require {
($invariant:expr, $error:tt $(,)?) => {
if !($invariant) {
return Err(anchor_lang::anchor_attribute_error::error!(
crate::ErrorCode::$error
));
return Err(anchor_lang::error!(crate::ErrorCode::$error));
}
};
($invariant:expr, $error:expr $(,)?) => {
if !($invariant) {
return Err(anchor_lang::anchor_attribute_error::error!($error));
return Err(anchor_lang::error!($error));
}
};
}
@ -566,12 +564,10 @@ macro_rules! require_gte {
#[macro_export]
macro_rules! err {
($error:tt $(,)?) => {
Err(anchor_lang::anchor_attribute_error::error!(
crate::ErrorCode::$error
))
Err(anchor_lang::error!(crate::ErrorCode::$error))
};
($error:expr $(,)?) => {
Err(anchor_lang::anchor_attribute_error::error!($error))
Err(anchor_lang::error!($error))
};
}

View File

@ -76,7 +76,7 @@ pub fn generate(error: Error) -> proc_macro2::TokenStream {
}
impl From<#enum_name> for anchor_lang::error::Error {
fn from(error_code: #enum_name) -> Error {
fn from(error_code: #enum_name) -> anchor_lang::error::Error {
anchor_lang::error::Error::from(
anchor_lang::error::AnchorError {
error_name: error_code.name(),