Skip to content

Commit

Permalink
Use less heap intensive error mapping (#2313)
Browse files Browse the repository at this point in the history
* less heap intensive error mapping

* add changelog

* try returning the error

* dumb match statements instead

* missing commas

Co-authored-by: henrye <henry@notanemail>
  • Loading branch information
Henry-E and henrye committed Dec 14, 2022
1 parent fad0580 commit f79f9da
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -49,6 +49,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- ts: Fixing breaking change where null or undefined wallet throws an error ([#2303](https://github.com/coral-xyz/anchor/pull/2303)).
- ts: Fixed `.fetchNullable()` to be robust towards accounts only holding a balance ([#2301](https://github.com/coral-xyz/anchor/pull/2301)).
- lang: Only add public enums to the IDL ([#2309](https://github.com/coral-xyz/anchor/pull/2309)).
- lang: Fix heap intensive error mapping ([#2313](https://github.com/coral-xyz/anchor/pull/2313)).

### Breaking

Expand Down
59 changes: 32 additions & 27 deletions lang/syn/src/lib.rs
Expand Up @@ -356,15 +356,17 @@ impl Field {
Ty::Account(AccountTy { boxed, .. }) => {
let stream = if checked {
quote! {
#container_ty::try_from(
&#field,
).map_err(|e| e.with_account_name(#field_str))?
match #container_ty::try_from(&#field) {
Ok(val) => val,
Err(e) => return Err(e.with_account_name(#field_str))
}
}
} else {
quote! {
#container_ty::try_from_unchecked(
&#field,
).map_err(|e| e.with_account_name(#field_str))?
match #container_ty::try_from_unchecked(&#field) {
Ok(val) => val,
Err(e) => return Err(e.with_account_name(#field_str))
}
}
};
if *boxed {
Expand All @@ -378,48 +380,51 @@ impl Field {
Ty::CpiAccount(_) => {
if checked {
quote! {
#container_ty::try_from(
&#field,
).map_err(|e| e.with_account_name(#field_str))?
match #container_ty::try_from(&#field) {
Ok(val) => val,
Err(e) => return Err(e.with_account_name(#field_str))
}
}
} else {
quote! {
#container_ty::try_from_unchecked(
&#field,
).map_err(|e| e.with_account_name(#field_str))?
match #container_ty::try_from_unchecked(&#field) {
Ok(val) => val,
Err(e) => return Err(e.with_account_name(#field_str))
}
}
}
}
Ty::AccountLoader(_) => {
if checked {
quote! {
#container_ty::try_from(
&#field,
).map_err(|e| e.with_account_name(#field_str))?
match #container_ty::try_from(&#field) {
Ok(val) => val,
Err(e) => return Err(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))?
match #container_ty::try_from_unchecked(#owner_addr, &#field) {
Ok(val) => val,
Err(e) => return Err(e.with_account_name(#field_str))
}
}
}
}
_ => {
if checked {
quote! {
#container_ty::try_from(
#owner_addr,
&#field,
).map_err(|e| e.with_account_name(#field_str))?
match #container_ty::try_from(#owner_addr, &#field) {
Ok(val) => val,
Err(e) => return Err(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))?
match #container_ty::try_from_unchecked(#owner_addr, &#field) {
Ok(val) => val,
Err(e) => return Err(e.with_account_name(#field_str))
}
}
}
}
Expand Down

1 comment on commit f79f9da

@vercel
Copy link

@vercel vercel bot commented on f79f9da Dec 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

anchor-docs – ./

anchor-docs-git-master-200ms.vercel.app
anchor-docs-200ms.vercel.app
www.anchor-lang.com
anchor-lang.com

Please sign in to comment.