Use less heap intensive error mapping (#2313)
* less heap intensive error mapping * add changelog * try returning the error * dumb match statements instead * missing commas Co-authored-by: henrye <henry@notanemail>
This commit is contained in:
parent
fad05805d8
commit
f79f9dab74
|
@ -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
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue