add account name to discriminator mismatch errors (#2020)

This commit is contained in:
Matthew Callens 2022-07-01 18:25:18 -04:00 committed by GitHub
parent df9627e952
commit f76112a41a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -87,6 +87,7 @@ pub fn account(
let account_strct = parse_macro_input!(input as syn::ItemStruct);
let account_name = &account_strct.ident;
let account_name_str = account_name.to_string();
let (impl_gen, type_gen, where_clause) = account_strct.generics.split_for_impl();
let discriminator: proc_macro2::TokenStream = {
@ -153,7 +154,7 @@ pub fn account(
}
let given_disc = &buf[..8];
if &#discriminator != given_disc {
return Err(anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch.into());
return Err(anchor_lang::error!(anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch).with_account_name(#account_name_str));
}
Self::try_deserialize_unchecked(buf)
}
@ -196,7 +197,7 @@ pub fn account(
}
let given_disc = &buf[..8];
if &#discriminator != given_disc {
return Err(anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch.into());
return Err(anchor_lang::error!(anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch).with_account_name(#account_name_str));
}
Self::try_deserialize_unchecked(buf)
}