use num_derive::FromPrimitive;
use solana_program_error::{ProgramError, ToStr};
use thiserror::Error;
#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
pub enum MplAgentToolsError {
#[error("Invalid System Program")]
InvalidSystemProgram,
#[error("Invalid instruction data")]
InvalidInstructionData,
#[error("Invalid account data")]
InvalidAccountData,
#[error("Invalid MPL Core Program")]
InvalidMplCoreProgram,
#[error("Invalid Core Asset")]
InvalidCoreAsset,
#[error("Executive Profile must be uninitialized")]
ExecutiveProfileMustBeUninitialized,
#[error("Invalid Execution Delegate Record Derivation")]
InvalidExecutionDelegateRecordDerivation,
#[error("Execution Delegate Record must be uninitialized")]
ExecutionDelegateRecordMustBeUninitialized,
#[error("Invalid Agent Identity")]
InvalidAgentIdentity,
#[error("Agent Identity not registered")]
AgentIdentityNotRegistered,
#[error("Asset owner must be the one to delegate execution")]
AssetOwnerMustBeTheOneToDelegateExecution,
#[error("Invalid Executive Profile Derivation")]
InvalidExecutiveProfileDerivation,
#[error("Execution Delegate Record must be initialized")]
ExecutionDelegateRecordMustBeInitialized,
#[error("Authority must be asset owner or executive to revoke")]
UnauthorizedRevoke,
#[error("Executive Profile must be initialized")]
ExecutiveProfileMustBeInitialized,
}
impl From<MplAgentToolsError> for ProgramError {
fn from(e: MplAgentToolsError) -> Self {
ProgramError::Custom(e as u32)
}
}
impl TryFrom<u32> for MplAgentToolsError {
type Error = ProgramError;
fn try_from(error: u32) -> Result<Self, Self::Error> {
match error {
0 => Ok(MplAgentToolsError::InvalidSystemProgram),
1 => Ok(MplAgentToolsError::InvalidInstructionData),
2 => Ok(MplAgentToolsError::InvalidAccountData),
3 => Ok(MplAgentToolsError::InvalidMplCoreProgram),
4 => Ok(MplAgentToolsError::InvalidCoreAsset),
5 => Ok(MplAgentToolsError::ExecutiveProfileMustBeUninitialized),
6 => Ok(MplAgentToolsError::InvalidExecutionDelegateRecordDerivation),
7 => Ok(MplAgentToolsError::ExecutionDelegateRecordMustBeUninitialized),
8 => Ok(MplAgentToolsError::InvalidAgentIdentity),
9 => Ok(MplAgentToolsError::AgentIdentityNotRegistered),
10 => Ok(MplAgentToolsError::AssetOwnerMustBeTheOneToDelegateExecution),
11 => Ok(MplAgentToolsError::InvalidExecutiveProfileDerivation),
12 => Ok(MplAgentToolsError::ExecutionDelegateRecordMustBeInitialized),
13 => Ok(MplAgentToolsError::UnauthorizedRevoke),
14 => Ok(MplAgentToolsError::ExecutiveProfileMustBeInitialized),
_ => Err(ProgramError::InvalidArgument),
}
}
}
impl ToStr for MplAgentToolsError {
fn to_str(&self) -> &'static str {
match self {
MplAgentToolsError::InvalidSystemProgram => "Invalid System Program",
MplAgentToolsError::InvalidInstructionData => "Invalid instruction data",
MplAgentToolsError::InvalidAccountData => "Invalid account data",
MplAgentToolsError::InvalidMplCoreProgram => "Invalid MPL Core Program",
MplAgentToolsError::InvalidCoreAsset => "Invalid Core Asset",
MplAgentToolsError::ExecutiveProfileMustBeUninitialized => {
"Executive Profile must be uninitialized"
}
MplAgentToolsError::InvalidExecutionDelegateRecordDerivation => {
"Invalid Execution Delegate Record Derivation"
}
MplAgentToolsError::ExecutionDelegateRecordMustBeUninitialized => {
"Execution Delegate Record must be uninitialized"
}
MplAgentToolsError::InvalidAgentIdentity => "Invalid Agent Identity",
MplAgentToolsError::AgentIdentityNotRegistered => "Agent Identity not registered",
MplAgentToolsError::AssetOwnerMustBeTheOneToDelegateExecution => {
"Asset owner must be the one to delegate execution"
}
MplAgentToolsError::InvalidExecutiveProfileDerivation => {
"Invalid Executive Profile Derivation"
}
MplAgentToolsError::ExecutionDelegateRecordMustBeInitialized => {
"Execution Delegate Record must be initialized"
}
MplAgentToolsError::UnauthorizedRevoke => {
"Authority must be asset owner or executive to revoke"
}
MplAgentToolsError::ExecutiveProfileMustBeInitialized => {
"Executive Profile must be initialized"
}
}
}
}