1use thiserror::Error;
2
3pub type ChainsawResult<T> = Result<T, ChainsawError>;
4
5#[derive(Error, Debug)]
6pub enum ChainsawError {
7 #[error("Format Error")]
8 FormatError(#[from] std::fmt::Error),
9 #[error("Borsh IO Error")]
10 BorshIoError(#[from] borsh::maybestd::io::Error),
11
12 #[error("Borsh failed to deserialize type '{1}' ({0}")]
13 BorshDeserializeTypeError(String, borsh::maybestd::io::Error, Vec<u8>),
14
15 #[error("Borsh failed to deserialize type '{0}' ({1})")]
16 CompositeDeserializeError(String, Box<ChainsawError>),
17
18 #[error("Borsh failed to deserialize type for field '{0}' ({1})")]
19 FieldDeserializeError(String, Box<ChainsawError>),
20
21 #[error("Borsh failed to deserialize type for enum variant '{0}' ({1})")]
22 EnumVariantDeserializeError(String, Box<ChainsawError>),
23
24 #[error("Borsh failed to deserialize type for struct '{0}' ({1})")]
25 StructDeserializeError(String, Box<ChainsawError>),
26
27 #[error("Borsh failed to deserialize type for enum '{0}' ({1})")]
28 EnumDeserializeError(String, Box<ChainsawError>),
29
30 #[error("Account {0} is requested to be deserialized but was not defined in the IDL")]
31 UnknownAccount(String),
32
33 #[error("Account with discriminator {0} is requested to be deserialized but was not defined in the IDL")]
34 UnknownDiscriminatedAccount(String),
35
36 #[error("Type {0} is referenced but was not defined in the IDL")]
37 CannotFindDefinedType(String),
38
39 #[error("Variant with discriminant {0} does not exist")]
40 InvalidEnumVariantDiscriminator(u8),
41
42 #[error("Unable to parse JSON")]
43 ParseJsonError(#[from] serde_json::Error),
44
45 #[cfg(feature = "bson")]
46 #[error("Raw Bson Error")]
47 RawBsonError(#[from] bson::raw::Error),
48
49 #[error("No IDL was added for the program {0}.")]
50 CannotFindAccountDeserializerForProgramId(String),
51
52 #[error("Unable to derive pubkey for the IDL to fetch")]
53 IdlPubkeyError(#[from] solana_program::pubkey::PubkeyError),
54
55 #[cfg(feature = "network")]
56 #[error("Solana client issue")]
57 IdlClientError(#[from] solana_client::client_error::ClientError),
58
59 #[cfg(feature = "network")]
60 #[error("Unable to fetch valid IDL data (got less than 8 bytes)")]
61 AnchorIdlDataNeedsToBeAtLeast8Bytes,
62
63 #[cfg(feature = "network")]
64 #[error(
65 "Unable to deserialize the IDL container account for address {0} at derived address {1} ({2})"
66 )]
67 IdlContainerAccountDeserializationError(String, String, String),
68
69 #[cfg(feature = "network")]
70 #[error("Unable to inflage IDl data ({0})")]
71 IdlContainerShouldContainZlibData(String),
72
73 #[cfg(feature = "network")]
74 #[error("The account '{0}' was not found on chain")]
75 AccountNotFound(String),
76}