gpl_governance_tools/
error.rs

1//! Error types
2
3use num_derive::FromPrimitive;
4use gemachain_program::{
5    decode_error::DecodeError,
6    msg,
7    program_error::{PrintProgramError, ProgramError},
8};
9use thiserror::Error;
10
11/// Errors that may be returned by the GovernanceTools
12#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
13pub enum GovernanceToolsError {
14    /// Account already initialized
15    #[error("Account already initialized")]
16    AccountAlreadyInitialized = 1100,
17
18    /// Account doesn't exist
19    #[error("Account doesn't exist")]
20    AccountDoesNotExist,
21
22    /// Invalid account owner
23    #[error("Invalid account owner")]
24    InvalidAccountOwner,
25
26    /// Invalid Account type
27    #[error("Invalid Account type")]
28    InvalidAccountType,
29}
30
31impl PrintProgramError for GovernanceToolsError {
32    fn print<E>(&self) {
33        msg!("GOVERNANCE-TOOLS-ERROR: {}", &self.to_string());
34    }
35}
36
37impl From<GovernanceToolsError> for ProgramError {
38    fn from(e: GovernanceToolsError) -> Self {
39        ProgramError::Custom(e as u32)
40    }
41}
42
43impl<T> DecodeError<T> for GovernanceToolsError {
44    fn type_of() -> &'static str {
45        "Governance Tools Error"
46    }
47}