Skip to main content

safe_rs/
error.rs

1//! Error types for safe-rs
2
3use alloy::primitives::Address;
4use thiserror::Error;
5
6/// Result type alias for safe-rs operations
7pub type Result<T> = std::result::Result<T, Error>;
8
9/// Errors that can occur when interacting with Safe smart accounts
10#[derive(Debug, Error)]
11pub enum Error {
12    /// Failed to connect to the RPC provider
13    #[error("Provider error: {0}")]
14    Provider(String),
15
16    /// Failed to fetch data from the blockchain
17    #[error("Failed to fetch {what}: {reason}")]
18    Fetch { what: &'static str, reason: String },
19
20    /// Invalid chain ID
21    #[error("Unsupported chain ID: {0}")]
22    UnsupportedChain(u64),
23
24    /// Safe contract not deployed at the given address
25    #[error("Safe not deployed at {0}")]
26    SafeNotDeployed(Address),
27
28    /// MultiSend contract not deployed
29    #[error("MultiSend contract not deployed at {0}")]
30    MultiSendNotDeployed(Address),
31
32    /// The signer is not an owner of the Safe
33    #[error("Signer {signer} is not an owner of Safe {safe}")]
34    NotOwner { signer: Address, safe: Address },
35
36    /// Invalid Safe configuration for single-owner operations
37    #[error("Safe threshold is {threshold}, expected 1 for single-owner operations")]
38    InvalidThreshold { threshold: u64 },
39
40    /// Transaction simulation failed
41    #[error("Simulation failed: {reason}")]
42    SimulationFailed { reason: String },
43
44    /// Transaction reverted during simulation
45    #[error("Transaction reverted during simulation: {reason}")]
46    SimulationReverted { reason: String },
47
48    /// Transaction execution failed
49    #[error("Execution failed: {reason}")]
50    ExecutionFailed { reason: String },
51
52    /// Transaction was rejected by the Safe
53    #[error("Safe rejected transaction: {reason}")]
54    SafeRejected { reason: String },
55
56    /// Signature generation failed
57    #[error("Failed to sign: {0}")]
58    Signing(String),
59
60    /// Encoding error
61    #[error("Encoding error: {0}")]
62    Encoding(String),
63
64    /// No calls added to multicall builder
65    #[error("No calls added to multicall builder")]
66    NoCalls,
67
68    /// Gas estimation failed
69    #[error("Gas estimation failed: {0}")]
70    GasEstimation(String),
71
72    /// ABI encoding/decoding error
73    #[error("ABI error: {0}")]
74    Abi(String),
75
76    /// EIP-712 signing error
77    #[error("EIP-712 error: {0}")]
78    Eip712(String),
79
80    /// Fork database error
81    #[error("Fork database error: {0}")]
82    ForkDb(String),
83
84    /// Revm execution error
85    #[error("Revm execution error: {0}")]
86    Revm(String),
87
88    /// Transaction send failed
89    #[error("Failed to send transaction {index}: {reason}")]
90    TransactionSendFailed { index: usize, reason: String },
91
92    /// EOA operation not supported (e.g., DelegateCall)
93    #[error("EOA does not support {operation} operation")]
94    UnsupportedEoaOperation { operation: String },
95
96    /// Invalid configuration
97    #[error("Invalid configuration: {0}")]
98    InvalidConfig(String),
99
100    /// Simulation was not performed
101    #[error("Simulation has not been performed - call simulate() first")]
102    SimulationNotPerformed,
103}
104
105impl From<alloy::transports::RpcError<alloy::transports::TransportErrorKind>> for Error {
106    fn from(err: alloy::transports::RpcError<alloy::transports::TransportErrorKind>) -> Self {
107        Error::Provider(err.to_string())
108    }
109}
110
111impl From<alloy::contract::Error> for Error {
112    fn from(err: alloy::contract::Error) -> Self {
113        Error::Provider(err.to_string())
114    }
115}
116
117impl From<alloy::signers::Error> for Error {
118    fn from(err: alloy::signers::Error) -> Self {
119        Error::Signing(err.to_string())
120    }
121}