1use thiserror::Error;
2
3pub type ChainparserResult<T> = Result<T, ChainparserError>;
4
5#[derive(Error, Debug)]
6pub enum ChainparserError {
7 #[error("Format Error")]
8 FormatError(#[from] std::fmt::Error),
9
10 #[error("Borsh IO Error")]
11 BorshIoError(#[from] borsh::maybestd::io::Error),
12
13 #[error("Solana Idl Error")]
14 SolanaIdlError(#[from] solana_idl::errors::IdlError),
15
16 #[error("Deserializer '{0}' is not supported by chainsaw")]
17 UnsupportedDeserializer(String),
18
19 #[error("Borsh failed to deserialize type '{1}' ({0}")]
20 BorshDeserializeTypeError(String, borsh::maybestd::io::Error, Vec<u8>),
21
22 #[error("Borsh failed to deserialize float '{1}' ({0} {2:?}")]
23 BorshDeserializeFloatError(String, borsh::maybestd::io::Error, Vec<u8>),
24
25 #[error("Chainparser failed to deserialize type '{0}' ({1} {2:?}")]
26 TryFromSliceError(String, std::array::TryFromSliceError, Vec<u8>),
27
28 #[error("Borsh failed to deserialize type '{0}' ({1})")]
29 CompositeDeserializeError(String, Box<ChainparserError>),
30
31 #[error("Borsh failed to deserialize type for field '{0}' ({1})")]
32 FieldDeserializeError(String, Box<ChainparserError>),
33
34 #[error("Borsh failed to deserialize type for enum variant '{0}' ({1})")]
35 EnumVariantDeserializeError(String, Box<ChainparserError>),
36
37 #[error("Borsh failed to deserialize type for struct '{0}' ({1})")]
38 StructDeserializeError(String, Box<ChainparserError>),
39
40 #[error("Borsh failed to deserialize type for enum '{0}' ({1})")]
41 EnumDeserializeError(String, Box<ChainparserError>),
42
43 #[error("The '{0}' deserializer does not support type '{1}'")]
44 DeserializerDoesNotSupportType(String, String),
45
46 #[error(
47 "Encountered '{1}' when trying to deserizalize type '{0}' from {2:?}"
48 )]
49 InvalidDataToDeserialize(String, String, Vec<u8>),
50
51 #[error("Account {0} is requested to be deserialized but was not defined in the IDL")]
52 UnknownAccount(String),
53
54 #[error("Account with discriminator {0} is requested to be deserialized but was not defined in the IDL")]
55 UnknownDiscriminatedAccount(String),
56
57 #[error(
58 "Could not find an account that matches the provided account data."
59 )]
60 CannotFindDeserializerForAccount,
61
62 #[error("Account is requested to be deserialized Idl {0} version {1} has no accounts")]
63 IdlHasNoAccountsAndCannotDeserializeAccountData(String, String),
64
65 #[error("Account is requested to be via discriminator bytes but Idl {0} version {1} has no such accounts")]
66 IdlHasNoAccountsDiscriminatedByDiscriminatorBytes(String, String),
67
68 #[error("Type {0} is referenced but was not defined in the IDL")]
69 CannotFindDefinedType(String),
70
71 #[error("Variant with discriminant {0} does not exist")]
72 InvalidEnumVariantDiscriminator(u8),
73
74 #[error("Unable to parse JSON")]
75 ParseJsonError(#[from] serde_json::Error),
76
77 #[cfg(feature = "bson")]
78 #[error("Raw Bson Error")]
79 RawBsonError(#[from] bson::raw::Error),
80
81 #[error("No IDL was added for the program {0}.")]
82 CannotFindAccountDeserializerForProgramId(String),
83
84 #[error("Unable to derive pubkey for the IDL to fetch")]
85 IdlPubkeyError(#[from] solana_sdk::pubkey::PubkeyError),
86
87 #[error("Unable to inflate IDl data ({0})")]
88 IdlContainerShouldContainZlibData(String),
89
90 #[error(
91 "Failed to parse pubkey of the program to add IDL for '{0}' ({1})"
92 )]
93 FailedToParseIdlProgramPubkey(String, String),
94
95 #[error(
96 "Cannot parse account data with {0} bytes since the discriminator is at least {1} bytes"
97 )]
98 AccountDataTooShortForDiscriminatorBytes(usize, usize),
99}