spl_governance_chat/
error.rs

1//! Error types
2
3use {
4    num_derive::FromPrimitive,
5    solana_program::{
6        decode_error::DecodeError,
7        msg,
8        program_error::{PrintProgramError, ProgramError},
9    },
10    thiserror::Error,
11};
12
13/// Errors that may be returned by the GovernanceChat program
14#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
15pub enum GovernanceChatError {
16    /// Owner doesn't have enough governing tokens to comment on Proposal
17    #[error("Owner doesn't have enough governing tokens to comment on Proposal")]
18    NotEnoughTokensToCommentProposal = 900,
19
20    /// Account already initialized
21    #[error("Account already initialized")]
22    AccountAlreadyInitialized,
23}
24
25impl PrintProgramError for GovernanceChatError {
26    fn print<E>(&self) {
27        msg!("GOVERNANCE-CHAT-ERROR: {}", &self.to_string());
28    }
29}
30
31impl From<GovernanceChatError> for ProgramError {
32    fn from(e: GovernanceChatError) -> Self {
33        ProgramError::Custom(e as u32)
34    }
35}
36
37impl<T> DecodeError<T> for GovernanceChatError {
38    fn type_of() -> &'static str {
39        "Governance Chat Error"
40    }
41}