Skip to content

Commit 1ed7279

Browse files
idl: Fix defined types with unsupported fields not producing an error (solana-foundation#4088)
1 parent 0cdaca1 commit 1ed7279

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ The minor version will be incremented upon a breaking change and the patch versi
1414

1515
### Fixes
1616

17+
- idl: Fix defined types with unsupported fields not producing an error ([#4088](https://github.com/solana-foundation/anchor/pull/4088)).
18+
1719
### Breaking
1820

1921
## [0.32.1] - 2025-10-09
@@ -24,7 +26,7 @@ The minor version will be incremented upon a breaking change and the patch versi
2426

2527
- lang: Fix deprecation warnings on alloc and add solana-program to prelude
2628
([#3975](https://github.com/solana-foundation/anchor/pull/3975)).
27-
- cli: Fix race condition that could happen when deploying a program
29+
- cli: Fix race condition that could happen when deploying a program
2830
([#3976](https://github.com/solana-foundation/anchor/pull/3976)).
2931

3032
### Breaking

lang/syn/src/idl/defined.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use anyhow::{anyhow, Result};
21
use proc_macro2::TokenStream;
32
use quote::quote;
3+
use syn::{spanned::Spanned, Result};
44

55
use super::common::{get_idl_module_path, get_no_docs};
66
use crate::parser::docs;
@@ -22,7 +22,7 @@ pub fn impl_idl_build_union(item: &syn::ItemUnion) -> TokenStream {
2222
impl_idl_build(
2323
&item.ident,
2424
&item.generics,
25-
Err(anyhow!("Unions are not supported")),
25+
Err(syn::Error::new_spanned(item, "Unions are not supported")),
2626
)
2727
}
2828

@@ -33,10 +33,11 @@ fn impl_idl_build(
3333
type_def: Result<(TokenStream, Vec<syn::TypePath>)>,
3434
) -> TokenStream {
3535
let idl = get_idl_module_path();
36-
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
3736
let idl_build_trait = quote!(anchor_lang::idl::build::IdlBuild);
37+
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
3838

3939
let (idl_type_def, insert_defined) = match type_def {
40+
Err(e) => return e.into_compile_error(),
4041
Ok((ts, defined)) => (
4142
quote! { Some(#ts) },
4243
quote! {
@@ -48,7 +49,6 @@ fn impl_idl_build(
4849
);*
4950
},
5051
),
51-
_ => (quote! { None }, quote! {}),
5252
};
5353

5454
quote! {
@@ -612,7 +612,12 @@ pub fn gen_idl_type(
612612
defined.extend(def);
613613
quote! { #idl::IdlGenericArg::Type { ty: #ty } }
614614
}
615-
_ => return Err(anyhow!("Unsupported generic argument: {arg:#?}")),
615+
_ => {
616+
return Err(syn::Error::new(
617+
arg.span(),
618+
"Unsupported generic argument",
619+
))
620+
}
616621
};
617622
generics.push(generic);
618623
}
@@ -635,7 +640,7 @@ pub fn gen_idl_type(
635640
}
636641
_ => gen_idl_type(&reference.elem, generic_params),
637642
},
638-
_ => Err(anyhow!("Unknown type: {ty:#?}")),
643+
_ => Err(syn::Error::new_spanned(ty, "Unsupported type")),
639644
}
640645
}
641646

0 commit comments

Comments
 (0)