From d0a13e653555a49bf038160ecd22fe0718e44c2a Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 20 Apr 2022 16:59:00 -0400 Subject: [PATCH] lang: fix missing account name info when deser fails when using 'init' or 'zero' (#1800) --- CHANGELOG.md | 1 + lang/syn/src/lib.rs | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81c49c5b4..24124ffa0 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 7bde237ce..25888c4cf 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))? } } }