Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lang/attribute/program/src/declare_program/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ fn gen_program(idl: &Idl, name: &syn::Ident) -> proc_macro2::TokenStream {
// Utils
let utils_mod = gen_utils_mod(idl);

let errors_re_export = if !idl.errors.is_empty() {
quote! {
pub use errors::ProgramError;
}
} else {
quote! {}
};

quote! {
#docs
pub mod #name {
Expand All @@ -88,6 +96,9 @@ fn gen_program(idl: &Idl, name: &syn::Ident) -> proc_macro2::TokenStream {
#types_mod
#errors_mod

// Re-export error types to make them easily accessible
#errors_re_export

#cpi_mod
#client_mod
#internal_mod
Expand Down
4 changes: 2 additions & 2 deletions lang/attribute/program/src/declare_program/mods/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn gen_account(idl: &Idl) -> proc_macro2::TokenStream {

fn try_from(value: &[u8]) -> Result<Self> {
#(#if_statements)*
Err(ProgramError::InvalidArgument.into())
Err(anchor_lang::prelude::ProgramError::InvalidArgument.into())
}
}
}
Expand Down Expand Up @@ -102,7 +102,7 @@ fn gen_event(idl: &Idl) -> proc_macro2::TokenStream {

fn try_from(value: &[u8]) -> Result<Self> {
#(#if_statements)*
Err(ProgramError::InvalidArgument.into())
Err(anchor_lang::prelude::ProgramError::InvalidArgument.into())
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions tests/declare-program/programs/declare-program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ pub mod declare_program {

Ok(())
}

pub fn test_amm_v3_errors(_ctx: Context<Utils>) -> Result<()> {
let _error: amm_v3::ProgramError = amm_v3::ProgramError::LOK;

let _error2: amm_v3::errors::ProgramError = amm_v3::errors::ProgramError::NotApproved;

Ok(())
}
}

#[derive(Accounts)]
Expand Down