add account name to discriminator mismatch errors (#2020)
This commit is contained in:
parent
df9627e952
commit
f76112a41a
|
@ -87,6 +87,7 @@ pub fn account(
|
||||||
|
|
||||||
let account_strct = parse_macro_input!(input as syn::ItemStruct);
|
let account_strct = parse_macro_input!(input as syn::ItemStruct);
|
||||||
let account_name = &account_strct.ident;
|
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 (impl_gen, type_gen, where_clause) = account_strct.generics.split_for_impl();
|
||||||
|
|
||||||
let discriminator: proc_macro2::TokenStream = {
|
let discriminator: proc_macro2::TokenStream = {
|
||||||
|
@ -153,7 +154,7 @@ pub fn account(
|
||||||
}
|
}
|
||||||
let given_disc = &buf[..8];
|
let given_disc = &buf[..8];
|
||||||
if &#discriminator != given_disc {
|
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)
|
Self::try_deserialize_unchecked(buf)
|
||||||
}
|
}
|
||||||
|
@ -196,7 +197,7 @@ pub fn account(
|
||||||
}
|
}
|
||||||
let given_disc = &buf[..8];
|
let given_disc = &buf[..8];
|
||||||
if &#discriminator != given_disc {
|
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)
|
Self::try_deserialize_unchecked(buf)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue