upgrade/
error.rs

1//! Error types
2
3use num_derive::FromPrimitive;
4use solana_program::{decode_error::DecodeError, msg, program_error::{PrintProgramError, ProgramError}};
5use thiserror::Error;
6
7/// Errors that may be returned by the Token program.
8#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
9pub enum UpgradeError {
10    /// 0 The account cannot be initialized because it is already being used.
11    #[error("Already in use")]
12    AlreadyInUse,
13    /// 1 The account hasn't been initialized
14    #[error("Not initialized")]
15    NotInitialized,
16    /// 2 Wrong admin account
17    #[error("Wrong admin")]
18    WrongAdmin,
19    /// 3 Wrong seeds for admin account
20    #[error("Wrong seeds")]
21    WrongSeeds,
22    /// 4 Wrong signature key
23    #[error("Wrong signature public key")]
24    WrongSignature,
25    /// 5 Invalid signature
26    #[error("Invalid signature")]
27    InvalidSignature,
28}
29
30
31impl From<UpgradeError> for ProgramError {
32    fn from(e: UpgradeError) -> Self {
33        ProgramError::Custom(e as u32)
34    }
35}
36
37impl PrintProgramError for UpgradeError {
38    fn print<E>(&self) {
39        msg!(&self.to_string());
40    }
41}
42
43impl<T> DecodeError<T> for UpgradeError {
44    fn type_of() -> &'static str {
45        "UpgradeError"
46    }
47}