1use std::{array::TryFromSliceError, str::Utf8Error};
2
3use fuel_tx::{CheckError, Receipt};
4use thiserror::Error;
5
6#[derive(Error, Debug)]
7pub enum Error {
8 #[error("Invalid data: {0}")]
9 InvalidData(String),
10 #[error("Serialization error: {0}")]
11 SerdeJson(#[from] serde_json::Error),
12 #[error("IO error: {0}")]
13 IOError(#[from] std::io::Error),
14 #[error("Invalid type: {0}")]
15 InvalidType(String),
16 #[error("Utf8 error: {0}")]
17 Utf8Error(#[from] Utf8Error),
18 #[error("Instantiation error: {0}")]
19 InstantiationError(String),
20 #[error("Infrastructure error: {0}")]
21 InfrastructureError(String),
22 #[error("Account error: {0}")]
23 AccountError(String),
24 #[error("Wallet error: {0}")]
25 WalletError(String),
26 #[error("Provider error: {0}")]
27 ProviderError(String),
28 #[error("Validation error: {0}")]
29 ValidationError(#[from] CheckError),
30 #[error("Tried to forward assets to a contract method that is not payable.")]
31 AssetsForwardedToNonPayableMethod,
32 #[error("Revert transaction error: {reason},\n receipts: {receipts:?}")]
33 RevertTransactionError {
34 reason: String,
35 revert_id: u64,
36 receipts: Vec<Receipt>,
37 },
38 #[error("Transaction is using predicates. Provide consensus parameters by using .set_consensus_parameters().")]
39 TransactionBuildError,
40}
41
42pub type Result<T> = std::result::Result<T, Error>;
43
44#[macro_export]
48macro_rules! error {
49 ($err_variant:ident, $fmt_str: literal $(,$arg: expr)*) => {
50 Error::$err_variant(format!($fmt_str,$($arg),*))
51 }
52}
53pub use error;
54
55macro_rules! impl_error_from {
56 ($err_variant:ident, $err_type:ty ) => {
57 impl From<$err_type> for Error {
58 fn from(err: $err_type) -> Error {
59 Error::$err_variant(err.to_string())
60 }
61 }
62 };
63}
64
65impl_error_from!(InvalidData, bech32::Error);
66impl_error_from!(InvalidData, TryFromSliceError);