Skip to content
Merged
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
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ edition = { workspace = true }
[dependencies]
bytemuck = "1.23.0"
num-derive = "0.4"
num_enum = "0.7"
num-traits = "0.2"
solana-decode-error = "2.2.1"
solana-instruction = "2.2.1"
solana-msg = "2.2.1"
solana-program-error = "2.2.1"
solana-program-error = "2.2.2"
solana-pubkey = "2.2.1"
spl-discriminator = "0.4.0"
spl-pod = "0.5.1"
Expand Down
50 changes: 19 additions & 31 deletions interface/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
//! Interface error types

use {
solana_decode_error::DecodeError,
solana_msg::msg,
solana_program_error::{PrintProgramError, ProgramError},
};
use solana_program_error::{ProgramError, ToStr};

/// Errors that may be returned by the interface.
#[repr(u32)]
#[derive(Clone, Debug, Eq, thiserror::Error, num_derive::FromPrimitive, PartialEq)]
#[derive(
Clone,
Debug,
Eq,
thiserror::Error,
num_derive::FromPrimitive,
num_enum::TryFromPrimitive,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if we want to generally recommend that people use this instead. Since ToStr requires that the enum implements TryFrom<u32>, this seemed like the easiest option.

If so, we should add that to the help text in the deprecation warning

Copy link

Choose a reason for hiding this comment

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

Agree, I think is a good idea to provide a recommendation. I wonder if we add something to the docs of the ToStr with an example will be easier to provide more context.

PartialEq,
)]
pub enum TokenGroupError {
/// Size is greater than proposed max size
#[error("Size is greater than proposed max size")]
Expand Down Expand Up @@ -36,39 +40,23 @@ impl From<TokenGroupError> for ProgramError {
}
}

impl<T> DecodeError<T> for TokenGroupError {
fn type_of() -> &'static str {
"TokenGroupError"
}
}

impl PrintProgramError for TokenGroupError {
fn print<E>(&self)
impl ToStr for TokenGroupError {
fn to_str<E>(&self) -> &'static str
where
E: 'static
+ std::error::Error
+ DecodeError<E>
+ PrintProgramError
+ num_traits::FromPrimitive,
E: 'static + ToStr + TryFrom<u32>,
{
match self {
TokenGroupError::SizeExceedsNewMaxSize => {
msg!("Size is greater than proposed max size")
}
TokenGroupError::SizeExceedsMaxSize => {
msg!("Size is greater than max size")
}
TokenGroupError::ImmutableGroup => {
msg!("Group is immutable")
}
TokenGroupError::SizeExceedsNewMaxSize => "Size is greater than proposed max size",
TokenGroupError::SizeExceedsMaxSize => "Size is greater than max size",
TokenGroupError::ImmutableGroup => "Group is immutable",
TokenGroupError::IncorrectMintAuthority => {
msg!("Incorrect mint authority has signed the instruction",)
"Incorrect mint authority has signed the instruction"
}
TokenGroupError::IncorrectUpdateAuthority => {
msg!("Incorrect update authority has signed the instruction",)
"Incorrect update authority has signed the instruction"
}
TokenGroupError::MemberAccountIsGroupAccount => {
msg!("Member account should not be the same as the group account",)
"Member account should not be the same as the group account"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ no-entrypoint = []
test-sbf = []

[dependencies]
solana-program-error = "2.2.2"
solana-program = "2.2.1"
spl-pod = "0.5.1"
spl-token-2022 = { version = "9.0.0", features = ["no-entrypoint"] }
Expand Down
8 changes: 3 additions & 5 deletions program/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

use {
crate::processor,
solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError,
pubkey::Pubkey,
},
solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, msg, pubkey::Pubkey},
solana_program_error::ToStr,
spl_token_group_interface::error::TokenGroupError,
};

Expand All @@ -16,7 +14,7 @@ fn process_instruction(
instruction_data: &[u8],
) -> ProgramResult {
if let Err(error) = processor::process(program_id, accounts, instruction_data) {
error.print::<TokenGroupError>();
msg!(error.to_str::<TokenGroupError>());
return Err(error);
}
Ok(())
Expand Down