150 lines
4.5 KiB
Rust
150 lines
4.5 KiB
Rust
//! Error types
|
|
|
|
use num_derive::FromPrimitive;
|
|
use solana_program::{
|
|
decode_error::DecodeError,
|
|
msg,
|
|
program_error::{PrintProgramError, ProgramError},
|
|
};
|
|
use thiserror::Error;
|
|
|
|
/// Errors that may be returned by the Governance program
|
|
#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
|
|
pub enum GovernanceError {
|
|
/// Invalid instruction passed to program
|
|
#[error("Invalid instruction passed to program")]
|
|
InvalidInstruction,
|
|
|
|
/// Realm with the given name and governing mints already exists
|
|
#[error("Realm with the given name and governing mints already exists")]
|
|
RealmAlreadyExists,
|
|
|
|
/// Invalid Realm
|
|
#[error("Invalid realm")]
|
|
InvalidRealm,
|
|
|
|
/// Invalid Governing Token Mint
|
|
#[error("Invalid Governing Token Mint")]
|
|
InvalidGoverningTokenMint,
|
|
|
|
/// Governing Token Owner must sign transaction
|
|
#[error("Governing Token Owner must sign transaction")]
|
|
GoverningTokenOwnerMustSign,
|
|
|
|
/// Governing Token Owner or Delegate must sign transaction
|
|
#[error("Governing Token Owner or Delegate must sign transaction")]
|
|
GoverningTokenOwnerOrDelegateMustSign,
|
|
|
|
/// All active votes must be relinquished to withdraw governing tokens
|
|
#[error("All active votes must be relinquished to withdraw governing tokens")]
|
|
CannotWithdrawGoverningTokensWhenActiveVotesExist,
|
|
|
|
/// Invalid Token Owner Record account address
|
|
#[error("Invalid Token Owner Record account address")]
|
|
InvalidTokenOwnerRecordAccountAddress,
|
|
|
|
/// Invalid Token Owner Record Governing mint
|
|
#[error("Invalid Token Owner Record Governing mint")]
|
|
InvalidTokenOwnerRecordGoverningMint,
|
|
|
|
/// Invalid Token Owner Record Realm
|
|
#[error("Invalid Token Owner Record Realm")]
|
|
InvalidTokenOwnerRecordRealm,
|
|
|
|
/// Invalid Signatory account address
|
|
#[error("Invalid Signatory account address")]
|
|
InvalidSignatoryAddress,
|
|
|
|
/// Signatory already signed off
|
|
#[error("Signatory already signed off")]
|
|
SignatoryAlreadySignedOff,
|
|
|
|
/// Signatory must sign
|
|
#[error("Signatory must sign")]
|
|
SignatoryMustSign,
|
|
|
|
/// Invalid Proposal Owner
|
|
#[error("Invalid Proposal Owner")]
|
|
InvalidProposalOwnerAccount,
|
|
|
|
/// Invalid Governance config
|
|
#[error("Invalid Governance config")]
|
|
InvalidGovernanceConfig,
|
|
|
|
/// Proposal for the given Governance, Governing Token Mint and index already exists
|
|
#[error("Proposal for the given Governance, Governing Token Mint and index already exists")]
|
|
ProposalAlreadyExists,
|
|
|
|
/// Owner doesn't have enough governing tokens to create Proposal
|
|
#[error("Owner doesn't have enough governing tokens to create Proposal")]
|
|
NotEnoughTokensToCreateProposal,
|
|
|
|
/// Invalid State: Can't edit Signatories
|
|
#[error("Invalid State: Can't edit Signatories")]
|
|
InvalidStateCannotEditSignatories,
|
|
|
|
/// Invalid State: Can't sign off
|
|
#[error("Invalid State: Can't sign off")]
|
|
InvalidStateCannotSignOff,
|
|
|
|
/// Invalid Signatory Mint
|
|
#[error("Invalid Signatory Mint")]
|
|
InvalidSignatoryMint,
|
|
|
|
/// ---- Account Tools Errors ----
|
|
|
|
/// Invalid account owner
|
|
#[error("Invalid account owner")]
|
|
InvalidAccountOwner,
|
|
|
|
/// Invalid Account type
|
|
#[error("Invalid Account type")]
|
|
InvalidAccountType,
|
|
|
|
/// ---- Token Tools Errors ----
|
|
|
|
/// Invalid Token account owner
|
|
#[error("Invalid Token account owner")]
|
|
InvalidTokenAccountOwner,
|
|
|
|
/// ---- Bpf Upgradable Loader Tools Errors ----
|
|
|
|
/// Invalid ProgramData account Address
|
|
#[error("Invalid ProgramData account address")]
|
|
InvalidProgramDataAccountAddress,
|
|
|
|
/// Invalid ProgramData account data
|
|
#[error("Invalid ProgramData account Data")]
|
|
InvalidProgramDataAccountData,
|
|
|
|
/// Provided upgrade authority doesn't match current program upgrade authority
|
|
#[error("Provided upgrade authority doesn't match current program upgrade authority")]
|
|
InvalidUpgradeAuthority,
|
|
|
|
/// Current program upgrade authority must sign transaction
|
|
#[error("Current program upgrade authority must sign transaction")]
|
|
UpgradeAuthorityMustSign,
|
|
|
|
/// Given program is not upgradable
|
|
#[error("Given program is not upgradable")]
|
|
ProgramNotUpgradable,
|
|
}
|
|
|
|
impl PrintProgramError for GovernanceError {
|
|
fn print<E>(&self) {
|
|
msg!("GOVERNANCE-ERROR: {}", &self.to_string());
|
|
}
|
|
}
|
|
|
|
impl From<GovernanceError> for ProgramError {
|
|
fn from(e: GovernanceError) -> Self {
|
|
ProgramError::Custom(e as u32)
|
|
}
|
|
}
|
|
|
|
impl<T> DecodeError<T> for GovernanceError {
|
|
fn type_of() -> &'static str {
|
|
"Governance Error"
|
|
}
|
|
}
|