diff --git a/CHANGELOG.md b/CHANGELOG.md index 81c49c5b43..24124ffa06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The minor version will be incremented upon a breaking change and the patch versi ### Fixes * cli: Move `overflow-checks` into workspace `Cargo.toml` so that it will not be ignored by compiler ([#1806](https://github.com/project-serum/anchor/pull/1806)). +* lang: Fix missing account name information when deserialization fails when using `init` or `zero` ([#1800](https://github.com/project-serum/anchor/pull/1800)). ## [0.24.2] - 2022-04-13 diff --git a/lang/syn/src/lib.rs b/lang/syn/src/lib.rs index 7bde237cea..25888c4cfd 100644 --- a/lang/syn/src/lib.rs +++ b/lang/syn/src/lib.rs @@ -287,6 +287,7 @@ impl Field { checked: bool, ) -> proc_macro2::TokenStream { let field = &self.ident; + let field_str = field.to_string(); let container_ty = self.container_ty(); let owner_addr = match &kind { None => quote! { program_id }, @@ -307,13 +308,13 @@ impl Field { quote! { #container_ty::try_from( &#field, - )? + ).map_err(|e| e.with_account_name(#field_str))? } } else { quote! { #container_ty::try_from_unchecked( &#field, - )? + ).map_err(|e| e.with_account_name(#field_str))? } }; if *boxed { @@ -329,13 +330,13 @@ impl Field { quote! { #container_ty::try_from( &#field, - )? + ).map_err(|e| e.with_account_name(#field_str))? } } else { quote! { #container_ty::try_from_unchecked( &#field, - )? + ).map_err(|e| e.with_account_name(#field_str))? } } } @@ -344,14 +345,14 @@ impl Field { quote! { #container_ty::try_from( &#field, - )? + ).map_err(|e| e.with_account_name(#field_str))? } } else { quote! { #container_ty::try_from_unchecked( #owner_addr, &#field, - )? + ).map_err(|e| e.with_account_name(#field_str))? } } } @@ -361,14 +362,14 @@ impl Field { #container_ty::try_from( #owner_addr, &#field, - )? + ).map_err(|e| e.with_account_name(#field_str))? } } else { quote! { #container_ty::try_from_unchecked( #owner_addr, &#field, - )? + ).map_err(|e| e.with_account_name(#field_str))? } } }