tensora/
errors.rs

1//! Error types for the Tensora SDK
2
3use thiserror::Error;
4
5/// Result type alias for Tensora SDK operations
6pub type Result<T> = std::result::Result<T, TensoraError>;
7
8/// Main error type for the Tensora SDK
9#[derive(Error, Debug)]
10pub enum TensoraError {
11    /// RPC provider error
12    #[error("RPC error: {0}")]
13    Rpc(String),
14
15    /// Contract interaction error
16    #[error("Contract error: {0}")]
17    Contract(String),
18
19    /// Invalid chain ID
20    #[error("Invalid chain ID: expected {expected}, got {actual}")]
21    InvalidChainId { expected: u64, actual: u64 },
22
23    /// Configuration error
24    #[error("Configuration error: {0}")]
25    Config(String),
26
27    /// Wallet/signing error
28    #[error("Wallet error: {0}")]
29    Wallet(String),
30
31    /// API client error
32    #[error("API error: {0}")]
33    Api(String),
34
35    /// Bridge operation error
36    #[error("Bridge error: {0}")]
37    Bridge(String),
38
39    /// BSC reorg detected
40    #[error("BSC reorg detected: finalization may take several minutes")]
41    BscReorg,
42
43    /// Invalid address format
44    #[error("Invalid address: {0}")]
45    InvalidAddress(String),
46
47    /// Insufficient balance
48    #[error("Insufficient balance: required {required}, available {available}")]
49    InsufficientBalance { required: String, available: String },
50
51    /// Transaction failed
52    #[error("Transaction failed: {0}")]
53    TransactionFailed(String),
54
55    /// HTTP request error
56    #[error("HTTP request error: {0}")]
57    Http(#[from] reqwest::Error),
58
59    /// JSON serialization/deserialization error
60    #[error("JSON error: {0}")]
61    Json(#[from] serde_json::Error),
62
63    /// Environment variable error
64    #[error("Environment variable error: {0}")]
65    Env(#[from] std::env::VarError),
66
67    /// IO error
68    #[error("IO error: {0}")]
69    Io(#[from] std::io::Error),
70
71    /// Generic error
72    #[error("{0}")]
73    Other(String),
74}
75
76impl From<ethers::providers::ProviderError> for TensoraError {
77    fn from(err: ethers::providers::ProviderError) -> Self {
78        TensoraError::Rpc(err.to_string())
79    }
80}
81
82impl From<ethers::contract::ContractError<ethers::providers::Provider<ethers::providers::Http>>> for TensoraError {
83    fn from(err: ethers::contract::ContractError<ethers::providers::Provider<ethers::providers::Http>>) -> Self {
84        TensoraError::Contract(err.to_string())
85    }
86}
87
88impl From<ethers::core::types::ParseBytesError> for TensoraError {
89    fn from(err: ethers::core::types::ParseBytesError) -> Self {
90        TensoraError::InvalidAddress(err.to_string())
91    }
92}
93
94impl From<String> for TensoraError {
95    fn from(err: String) -> Self {
96        TensoraError::Other(err)
97    }
98}
99
100impl From<&str> for TensoraError {
101    fn from(err: &str) -> Self {
102        TensoraError::Other(err.to_string())
103    }
104}
105