Pārlūkot izejas kodu

lang: fix error mod exports (#1426)

Paul 3 gadi atpakaļ
vecāks
revīzija
2390a4f167

+ 7 - 7
lang/attribute/account/src/lib.rs

@@ -148,11 +148,11 @@ pub fn account(
                 impl #impl_gen anchor_lang::AccountDeserialize for #account_name #type_gen #where_clause {
                     fn try_deserialize(buf: &mut &[u8]) -> std::result::Result<Self, ProgramError> {
                         if buf.len() < #discriminator.len() {
-                            return Err(anchor_lang::__private::ErrorCode::AccountDiscriminatorNotFound.into());
+                            return Err(anchor_lang::error::ErrorCode::AccountDiscriminatorNotFound.into());
                         }
                         let given_disc = &buf[..8];
                         if &#discriminator != given_disc {
-                            return Err(anchor_lang::__private::ErrorCode::AccountDiscriminatorMismatch.into());
+                            return Err(anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch.into());
                         }
                         Self::try_deserialize_unchecked(buf)
                     }
@@ -176,12 +176,12 @@ pub fn account(
                 #[automatically_derived]
                 impl #impl_gen anchor_lang::AccountSerialize for #account_name #type_gen #where_clause {
                     fn try_serialize<W: std::io::Write>(&self, writer: &mut W) -> std::result::Result<(), ProgramError> {
-                        writer.write_all(&#discriminator).map_err(|_| anchor_lang::__private::ErrorCode::AccountDidNotSerialize)?;
+                        writer.write_all(&#discriminator).map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotSerialize)?;
                         AnchorSerialize::serialize(
                             self,
                             writer
                         )
-                            .map_err(|_| anchor_lang::__private::ErrorCode::AccountDidNotSerialize)?;
+                            .map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotSerialize)?;
                         Ok(())
                     }
                 }
@@ -190,11 +190,11 @@ pub fn account(
                 impl #impl_gen anchor_lang::AccountDeserialize for #account_name #type_gen #where_clause {
                     fn try_deserialize(buf: &mut &[u8]) -> std::result::Result<Self, ProgramError> {
                         if buf.len() < #discriminator.len() {
-                            return Err(anchor_lang::__private::ErrorCode::AccountDiscriminatorNotFound.into());
+                            return Err(anchor_lang::error::ErrorCode::AccountDiscriminatorNotFound.into());
                         }
                         let given_disc = &buf[..8];
                         if &#discriminator != given_disc {
-                            return Err(anchor_lang::__private::ErrorCode::AccountDiscriminatorMismatch.into());
+                            return Err(anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch.into());
                         }
                         Self::try_deserialize_unchecked(buf)
                     }
@@ -202,7 +202,7 @@ pub fn account(
                     fn try_deserialize_unchecked(buf: &mut &[u8]) -> std::result::Result<Self, ProgramError> {
                         let mut data: &[u8] = &buf[8..];
                         AnchorDeserialize::deserialize(&mut data)
-                            .map_err(|_| anchor_lang::__private::ErrorCode::AccountDidNotDeserialize.into())
+                            .map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotDeserialize.into())
                     }
                 }
 

+ 1 - 1
lang/attribute/interface/src/lib.rs

@@ -208,7 +208,7 @@ pub fn interface(
                             #(#args_no_tys),*
                         };
                         let mut ix_data = anchor_lang::AnchorSerialize::try_to_vec(&ix)
-                            .map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotSerialize)?;
+                            .map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotSerialize)?;
                         let mut data = #sighash_tts.to_vec();
                         data.append(&mut ix_data);
                         let accounts = ctx.to_account_metas(None);

+ 1 - 1
lang/attribute/state/src/lib.rs

@@ -45,7 +45,7 @@ pub fn state(
                     fn size(&self) -> std::result::Result<u64, anchor_lang::solana_program::program_error::ProgramError> {
                         Ok(8 + self
                            .try_to_vec()
-                           .map_err(|_| anchor_lang::__private::ErrorCode::AccountDidNotSerialize)?
+                           .map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotSerialize)?
                            .len() as u64)
                     }
                 }

+ 4 - 1
lang/src/error.rs

@@ -1,5 +1,8 @@
 use crate::error;
 
+/// The starting point for user defined error codes.
+pub const ERROR_CODE_OFFSET: u32 = 6000;
+
 /// Error codes that can be returned by internal framework code.
 ///
 /// - &gt;= 100 Instruction error codes
@@ -10,7 +13,7 @@ use crate::error;
 /// - = 5000 deprecated error code
 ///
 /// The starting point for user-defined errors is defined
-/// by the [ERROR_CODE_OFFSET](crate::__private::ERROR_CODE_OFFSET).
+/// by the [ERROR_CODE_OFFSET](crate::error::ERROR_CODE_OFFSET).
 #[error(offset = 0)]
 pub enum ErrorCode {
     // Instructions

+ 0 - 9
lang/src/lib.rs

@@ -271,20 +271,11 @@ pub mod prelude {
 /// Internal module used by macros and unstable apis.
 #[doc(hidden)]
 pub mod __private {
-    // Modules with useful information for users
-    // don't use #[doc(hidden)] on these
-    pub use crate::error::ErrorCode;
-
     /// The discriminator anchor uses to mark an account as closed.
     pub const CLOSED_ACCOUNT_DISCRIMINATOR: [u8; 8] = [255, 255, 255, 255, 255, 255, 255, 255];
 
-    /// The starting point for user defined error codes.
-    pub const ERROR_CODE_OFFSET: u32 = 6000;
-
     pub use crate::ctor::Ctor;
 
-    pub use crate::error::Error;
-
     pub use anchor_attribute_account::ZeroCopyAccessor;
 
     pub use anchor_attribute_event::EventIndex;

+ 26 - 26
lang/syn/src/codegen/accounts/constraints.rs

@@ -157,7 +157,7 @@ pub fn generate_constraint_zeroed(f: &Field, _c: &ConstraintZeroed) -> proc_macr
             __disc_bytes.copy_from_slice(&__data[..8]);
             let __discriminator = u64::from_le_bytes(__disc_bytes);
             if __discriminator != 0 {
-                return Err(anchor_lang::__private::ErrorCode::ConstraintZero.into());
+                return Err(anchor_lang::error::ErrorCode::ConstraintZero.into());
             }
             #from_account_info
         };
@@ -169,7 +169,7 @@ pub fn generate_constraint_close(f: &Field, c: &ConstraintClose) -> proc_macro2:
     let target = &c.sol_dest;
     quote! {
         if #field.key() == #target.key() {
-            return Err(anchor_lang::__private::ErrorCode::ConstraintClose.into());
+            return Err(anchor_lang::error::ErrorCode::ConstraintClose.into());
         }
     }
 }
@@ -232,7 +232,7 @@ pub fn generate_constraint_literal(c: &ConstraintLiteral) -> proc_macro2::TokenS
     };
     quote! {
         if !(#lit) {
-            return Err(anchor_lang::__private::ErrorCode::Deprecated.into());
+            return Err(anchor_lang::error::ErrorCode::Deprecated.into());
         }
     }
 }
@@ -270,7 +270,7 @@ pub fn generate_constraint_rent_exempt(
         ConstraintRentExempt::Skip => quote! {},
         ConstraintRentExempt::Enforce => quote! {
             if !__anchor_rent.is_exempt(#info.lamports(), #info.try_data_len()?) {
-                return Err(anchor_lang::__private::ErrorCode::ConstraintRentExempt.into());
+                return Err(anchor_lang::error::ErrorCode::ConstraintRentExempt.into());
             }
         },
     }
@@ -367,10 +367,10 @@ fn generate_constraint_init_group(f: &Field, c: &ConstraintInitGroup) -> proc_ma
                     let pa: #ty_decl = #from_account_info;
                     if #if_needed {
                         if pa.mint != #mint.key() {
-                            return Err(anchor_lang::__private::ErrorCode::ConstraintTokenMint.into());
+                            return Err(anchor_lang::error::ErrorCode::ConstraintTokenMint.into());
                         }
                         if pa.owner != #owner.key() {
-                            return Err(anchor_lang::__private::ErrorCode::ConstraintTokenOwner.into());
+                            return Err(anchor_lang::error::ErrorCode::ConstraintTokenOwner.into());
                         }
                     }
                     pa
@@ -402,14 +402,14 @@ fn generate_constraint_init_group(f: &Field, c: &ConstraintInitGroup) -> proc_ma
                     let pa: #ty_decl = #from_account_info;
                     if #if_needed {
                         if pa.mint != #mint.key() {
-                            return Err(anchor_lang::__private::ErrorCode::ConstraintTokenMint.into());
+                            return Err(anchor_lang::error::ErrorCode::ConstraintTokenMint.into());
                         }
                         if pa.owner != #owner.key() {
-                            return Err(anchor_lang::__private::ErrorCode::ConstraintTokenOwner.into());
+                            return Err(anchor_lang::error::ErrorCode::ConstraintTokenOwner.into());
                         }
 
                         if pa.key() != anchor_spl::associated_token::get_associated_token_address(&#owner.key(), &#mint.key()) {
-                            return Err(anchor_lang::__private::ErrorCode::AccountNotAssociatedTokenAccount.into());
+                            return Err(anchor_lang::error::ErrorCode::AccountNotAssociatedTokenAccount.into());
                         }
                     }
                     pa
@@ -455,16 +455,16 @@ fn generate_constraint_init_group(f: &Field, c: &ConstraintInitGroup) -> proc_ma
                     let pa: #ty_decl = #from_account_info;
                     if #if_needed {
                         if pa.mint_authority != anchor_lang::solana_program::program_option::COption::Some(#owner.key()) {
-                            return Err(anchor_lang::__private::ErrorCode::ConstraintMintMintAuthority.into());
+                            return Err(anchor_lang::error::ErrorCode::ConstraintMintMintAuthority.into());
                         }
                         if pa.freeze_authority
                             .as_ref()
                             .map(|fa| #freeze_authority.as_ref().map(|expected_fa| fa != *expected_fa).unwrap_or(true))
                             .unwrap_or(#freeze_authority.is_some()) {
-                            return Err(anchor_lang::__private::ErrorCode::ConstraintMintFreezeAuthority.into());
+                            return Err(anchor_lang::error::ErrorCode::ConstraintMintFreezeAuthority.into());
                         }
                         if pa.decimals != #decimals {
-                            return Err(anchor_lang::__private::ErrorCode::ConstraintMintDecimals.into());
+                            return Err(anchor_lang::error::ErrorCode::ConstraintMintDecimals.into());
                         }
                     }
                     pa
@@ -540,17 +540,17 @@ fn generate_constraint_init_group(f: &Field, c: &ConstraintInitGroup) -> proc_ma
                     // Assert the account was created correctly.
                     if #if_needed {
                         if space != actual_field.data_len() {
-                            return Err(anchor_lang::__private::ErrorCode::ConstraintSpace.into());
+                            return Err(anchor_lang::error::ErrorCode::ConstraintSpace.into());
                         }
 
                         if actual_owner != #owner {
-                            return Err(anchor_lang::__private::ErrorCode::ConstraintOwner.into());
+                            return Err(anchor_lang::error::ErrorCode::ConstraintOwner.into());
                         }
 
                         {
                             let required_lamports = __anchor_rent.minimum_balance(space);
                             if pa.to_account_info().lamports() < required_lamports {
-                                return Err(anchor_lang::__private::ErrorCode::ConstraintRentExempt.into());
+                                return Err(anchor_lang::error::ErrorCode::ConstraintRentExempt.into());
                             }
                         }
                     }
@@ -592,10 +592,10 @@ fn generate_constraint_seeds(f: &Field, c: &ConstraintSeedsGroup) -> proc_macro2
         let b = c.bump.as_ref().unwrap();
         quote! {
             if #name.key() != __pda_address {
-                return Err(anchor_lang::__private::ErrorCode::ConstraintSeeds.into());
+                return Err(anchor_lang::error::ErrorCode::ConstraintSeeds.into());
             }
             if __bump != #b {
-                return Err(anchor_lang::__private::ErrorCode::ConstraintSeeds.into());
+                return Err(anchor_lang::error::ErrorCode::ConstraintSeeds.into());
             }
         }
     }
@@ -607,7 +607,7 @@ fn generate_constraint_seeds(f: &Field, c: &ConstraintSeedsGroup) -> proc_macro2
     else if c.is_init {
         quote! {
             if #name.key() != __pda_address {
-                return Err(anchor_lang::__private::ErrorCode::ConstraintSeeds.into());
+                return Err(anchor_lang::error::ErrorCode::ConstraintSeeds.into());
             }
         }
     }
@@ -630,7 +630,7 @@ fn generate_constraint_seeds(f: &Field, c: &ConstraintSeedsGroup) -> proc_macro2
                 let __pda_address = Pubkey::create_program_address(
                     &[#maybe_seeds_plus_comma &[#b][..]],
                     &#deriving_program_id,
-                ).map_err(|_| anchor_lang::__private::ErrorCode::ConstraintSeeds)?;
+                ).map_err(|_| anchor_lang::error::ErrorCode::ConstraintSeeds)?;
             },
         };
         quote! {
@@ -639,7 +639,7 @@ fn generate_constraint_seeds(f: &Field, c: &ConstraintSeedsGroup) -> proc_macro2
 
             // Check it.
             if #name.key() != __pda_address {
-                return Err(anchor_lang::__private::ErrorCode::ConstraintSeeds.into());
+                return Err(anchor_lang::error::ErrorCode::ConstraintSeeds.into());
             }
         }
     }
@@ -654,11 +654,11 @@ fn generate_constraint_associated_token(
     let spl_token_mint_address = &c.mint;
     quote! {
         if #name.owner != #wallet_address.key() {
-            return Err(anchor_lang::__private::ErrorCode::ConstraintTokenOwner.into());
+            return Err(anchor_lang::error::ErrorCode::ConstraintTokenOwner.into());
         }
         let __associated_token_address = anchor_spl::associated_token::get_associated_token_address(&#wallet_address.key(), &#spl_token_mint_address.key());
         if #name.key() != __associated_token_address {
-            return Err(anchor_lang::__private::ErrorCode::ConstraintAssociated.into());
+            return Err(anchor_lang::error::ErrorCode::ConstraintAssociated.into());
         }
     }
 }
@@ -753,7 +753,7 @@ pub fn generate_constraint_executable(
     let name = &f.ident;
     quote! {
         if !#name.to_account_info().executable {
-            return Err(anchor_lang::__private::ErrorCode::ConstraintExecutable.into());
+            return Err(anchor_lang::error::ErrorCode::ConstraintExecutable.into());
         }
     }
 }
@@ -769,10 +769,10 @@ pub fn generate_constraint_state(f: &Field, c: &ConstraintState) -> proc_macro2:
         // Checks the given state account is the canonical state account for
         // the target program.
         if #ident.key() != anchor_lang::accounts::cpi_state::CpiState::<#account_ty>::address(&#program_target.key()) {
-            return Err(anchor_lang::__private::ErrorCode::ConstraintState.into());
+            return Err(anchor_lang::error::ErrorCode::ConstraintState.into());
         }
         if #ident.as_ref().owner != &#program_target.key() {
-            return Err(anchor_lang::__private::ErrorCode::ConstraintState.into());
+            return Err(anchor_lang::error::ErrorCode::ConstraintState.into());
         }
     }
 }
@@ -783,6 +783,6 @@ fn generate_custom_error(
 ) -> proc_macro2::TokenStream {
     match custom_error {
         Some(error) => quote! { #error.into() },
-        None => quote! { anchor_lang::__private::ErrorCode::#error.into() },
+        None => quote! { anchor_lang::error::ErrorCode::#error.into() },
     }
 }

+ 1 - 1
lang/syn/src/codegen/accounts/try_accounts.rs

@@ -79,7 +79,7 @@ pub fn generate(accs: &AccountsStruct) -> proc_macro2::TokenStream {
                 let __Args {
                     #(#field_names),*
                 } = __Args::deserialize(&mut ix_data)
-                    .map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
+                    .map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotDeserialize)?;
             }
         }
     };

+ 1 - 1
lang/syn/src/codegen/error.rs

@@ -33,7 +33,7 @@ pub fn generate(error: Error) -> proc_macro2::TokenStream {
         .collect();
 
     let offset = match error.args {
-        None => quote! { anchor_lang::__private::ERROR_CODE_OFFSET},
+        None => quote! { anchor_lang::error::ERROR_CODE_OFFSET},
         Some(args) => {
             let offset = &args.offset;
             quote! { #offset }

+ 1 - 1
lang/syn/src/codegen/program/cpi.rs

@@ -78,7 +78,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
                         let ix = {
                             let ix = instruction::#ix_variant;
                             let mut ix_data = AnchorSerialize::try_to_vec(&ix)
-                                .map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotSerialize)?;
+                                .map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotSerialize)?;
                             let mut data = #sighash_tts.to_vec();
                             data.append(&mut ix_data);
                             let accounts = ctx.to_account_metas(None);

+ 1 - 1
lang/syn/src/codegen/program/dispatch.rs

@@ -114,7 +114,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
         })
         .collect();
     let fallback_fn = gen_fallback(program).unwrap_or(quote! {
-        Err(anchor_lang::__private::ErrorCode::InstructionFallbackNotFound.into())
+        Err(anchor_lang::error::ErrorCode::InstructionFallbackNotFound.into())
     });
     quote! {
         /// Performs method dispatch.

+ 1 - 1
lang/syn/src/codegen/program/entry.rs

@@ -6,7 +6,7 @@ use quote::quote;
 pub fn generate(program: &Program) -> proc_macro2::TokenStream {
     let name: proc_macro2::TokenStream = program.name.to_string().to_camel_case().parse().unwrap();
     let fallback_maybe = dispatch::gen_fallback(program).unwrap_or(quote! {
-        Err(anchor_lang::__private::ErrorCode::InstructionMissing.into());
+        Err(anchor_lang::error::ErrorCode::InstructionMissing.into());
     });
     quote! {
         #[cfg(not(feature = "no-entrypoint"))]

+ 12 - 12
lang/syn/src/codegen/program/handlers.rs

@@ -21,7 +21,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
                 let mut data: &[u8] = idl_ix_data;
 
                 let ix = anchor_lang::idl::IdlInstruction::deserialize(&mut data)
-                    .map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
+                    .map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotDeserialize)?;
 
                 match ix {
                     anchor_lang::idl::IdlInstruction::Create { data_len } => {
@@ -66,7 +66,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
             #[inline(never)]
             #[cfg(feature = "no-idl")]
             pub fn __idl_dispatch(program_id: &Pubkey, accounts: &[AccountInfo], idl_ix_data: &[u8]) -> ProgramResult {
-                Err(anchor_lang::__private::ErrorCode::IdlInstructionStub.into())
+                Err(anchor_lang::error::ErrorCode::IdlInstructionStub.into())
             }
 
             // One time IDL account initializer. Will faill on subsequent
@@ -81,7 +81,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
                 anchor_lang::prelude::msg!("Instruction: IdlCreateAccount");
 
                 if program_id != accounts.program.key {
-                    return Err(anchor_lang::__private::ErrorCode::IdlInstructionInvalidProgram.into());
+                    return Err(anchor_lang::error::ErrorCode::IdlInstructionInvalidProgram.into());
                 }
                 // Create the IDL's account.
                 let from = accounts.from.key;
@@ -212,7 +212,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
 
                             // Deserialize instruction data.
                             let ix = instruction::state::#ix_name::deserialize(&mut &ix_data[..])
-                                .map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
+                                .map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotDeserialize)?;
                             let instruction::state::#variant_arm = ix;
 
                             let mut __bumps = std::collections::BTreeMap::new();
@@ -291,7 +291,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
 
                             // Deserialize instruction data.
                             let ix = instruction::state::#ix_name::deserialize(&mut &ix_data[..])
-                                .map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
+                                .map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotDeserialize)?;
                             let instruction::state::#variant_arm = ix;
 
                             let mut __bumps = std::collections::BTreeMap::new();
@@ -399,7 +399,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
 
                                     // Deserialize instruction.
                                     let ix = instruction::state::#ix_name::deserialize(&mut &ix_data[..])
-                                        .map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
+                                        .map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotDeserialize)?;
                                     let instruction::state::#variant_arm = ix;
 
                                     // Bump collector.
@@ -408,7 +408,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
                                     // Load state.
                                     let mut remaining_accounts: &[AccountInfo] = accounts;
                                     if remaining_accounts.is_empty() {
-                                        return Err(anchor_lang::__private::ErrorCode::AccountNotEnoughKeys.into());
+                                        return Err(anchor_lang::error::ErrorCode::AccountNotEnoughKeys.into());
                                     }
                                     let loader: anchor_lang::accounts::loader::Loader<#mod_name::#name> = anchor_lang::accounts::loader::Loader::try_accounts(program_id, &mut remaining_accounts, &[], &mut __bumps)?;
 
@@ -455,7 +455,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
 
                                     // Deserialize instruction.
                                     let ix = instruction::state::#ix_name::deserialize(&mut &ix_data[..])
-                                        .map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
+                                        .map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotDeserialize)?;
                                     let instruction::state::#variant_arm = ix;
 
                                     // Bump collector.
@@ -464,7 +464,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
                                     // Load state.
                                     let mut remaining_accounts: &[AccountInfo] = accounts;
                                     if remaining_accounts.is_empty() {
-                                        return Err(anchor_lang::__private::ErrorCode::AccountNotEnoughKeys.into());
+                                        return Err(anchor_lang::error::ErrorCode::AccountNotEnoughKeys.into());
                                     }
                                     let mut state: anchor_lang::accounts::state::ProgramState<#state_ty> = anchor_lang::accounts::state::ProgramState::try_accounts(
                                         program_id,
@@ -566,7 +566,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
                                 let deserialize_instruction = quote! {
                                     #args_struct
                                     let ix = Args::deserialize(&mut &ix_data[..])
-                                        .map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
+                                        .map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotDeserialize)?;
                                     let Args {
                                         #(#ix_arg_names),*
                                     } = ix;
@@ -592,7 +592,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
                                             // Deserialize the program state account.
                                             let mut remaining_accounts: &[AccountInfo] = accounts;
                                             if remaining_accounts.is_empty() {
-                                                return Err(anchor_lang::__private::ErrorCode::AccountNotEnoughKeys.into());
+                                                return Err(anchor_lang::error::ErrorCode::AccountNotEnoughKeys.into());
                                             }
                                             let mut state: anchor_lang::accounts::state::ProgramState<#state_ty> = anchor_lang::accounts::state::ProgramState::try_accounts(
                                                 program_id,
@@ -705,7 +705,7 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
 
                     // Deserialize data.
                     let ix = instruction::#ix_name::deserialize(&mut &ix_data[..])
-                        .map_err(|_| anchor_lang::__private::ErrorCode::InstructionDidNotDeserialize)?;
+                        .map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotDeserialize)?;
                     let instruction::#variant_arm = ix;
 
                     // Bump collector.

+ 4 - 4
spl/src/governance.rs

@@ -11,9 +11,9 @@ macro_rules! vote_weight_record {
                 let mut data = buf;
                 let vwr: spl_governance_addin_api::voter_weight::VoterWeightRecord =
                     anchor_lang::AnchorDeserialize::deserialize(&mut data)
-                        .map_err(|_| anchor_lang::__private::ErrorCode::AccountDidNotDeserialize)?;
+                        .map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotDeserialize)?;
                 if !solana_program::program_pack::IsInitialized::is_initialized(&vwr) {
-                    return Err(anchor_lang::__private::ErrorCode::AccountDidNotSerialize.into());
+                    return Err(anchor_lang::error::ErrorCode::AccountDidNotSerialize.into());
                 }
                 Ok(VoterWeightRecord(vwr))
             }
@@ -24,7 +24,7 @@ macro_rules! vote_weight_record {
                 let mut data = buf;
                 let vwr: spl_governance_addin_api::voter_weight::VoterWeightRecord =
                     anchor_lang::AnchorDeserialize::deserialize(&mut data)
-                        .map_err(|_| anchor_lang::__private::ErrorCode::AccountDidNotDeserialize)?;
+                        .map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotDeserialize)?;
                 Ok(VoterWeightRecord(vwr))
             }
         }
@@ -35,7 +35,7 @@ macro_rules! vote_weight_record {
                 writer: &mut W,
             ) -> std::result::Result<(), ProgramError> {
                 anchor_lang::AnchorSerialize::serialize(&self.0, writer)
-                    .map_err(|_| anchor_lang::__private::ErrorCode::AccountDidNotSerialize)?;
+                    .map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotSerialize)?;
                 Ok(())
             }
         }