1
+ use crate :: defs:: AddressDef ;
1
2
use alloy:: {
2
3
primitives:: Address ,
3
4
transports:: {
4
5
RpcError as AlloyRpcError , TransportErrorKind , http:: reqwest:: header:: InvalidHeaderValue ,
5
6
} ,
6
7
} ;
8
+ use schemars:: JsonSchema ;
7
9
use serde:: { Deserialize , Serialize } ;
8
10
use thirdweb_core:: error:: ThirdwebError ;
9
11
use thiserror:: Error ;
10
12
use twmq:: error:: TwmqError ;
11
13
12
14
use crate :: chain:: Chain ;
13
15
14
- #[ derive( Debug , Error , Clone , Serialize , Deserialize ) ]
16
+ #[ derive( Debug , Error , Clone , Serialize , Deserialize , JsonSchema ) ]
15
17
pub enum RpcErrorKind {
16
18
/// Server returned an error response.
17
19
#[ error( "server returned an error response: {0}" ) ]
@@ -56,7 +58,7 @@ pub enum RpcErrorKind {
56
58
OtherTransportError ( String ) ,
57
59
}
58
60
59
- #[ derive( Debug , Serialize , Deserialize , Clone ) ]
61
+ #[ derive( Debug , Serialize , Deserialize , Clone , JsonSchema ) ]
60
62
pub struct RpcErrorResponse {
61
63
/// The error code.
62
64
pub code : i64 ,
@@ -80,7 +82,7 @@ impl RpcErrorResponse {
80
82
}
81
83
}
82
84
83
- #[ derive( Debug , Serialize , Deserialize ) ]
85
+ #[ derive( Debug , Serialize , Deserialize , JsonSchema ) ]
84
86
pub struct RpcErrorInfo {
85
87
/// The chain ID where the error occurred
86
88
pub chain_id : u64 ,
@@ -97,7 +99,7 @@ pub struct RpcErrorInfo {
97
99
}
98
100
99
101
/// A serializable contract interaction error type
100
- #[ derive( Debug , Error , Serialize , Deserialize , Clone ) ]
102
+ #[ derive( Debug , Error , Serialize , Deserialize , Clone , JsonSchema ) ]
101
103
pub enum ContractInteractionErrorKind {
102
104
/// Unknown function referenced.
103
105
#[ error( "unknown function: function {0} does not exist" ) ]
@@ -135,9 +137,29 @@ pub enum ContractInteractionErrorKind {
135
137
/// An error occured while waiting for a pending transaction.
136
138
#[ error( "pending transaction error: {0}" ) ]
137
139
PendingTransactionError ( String ) ,
140
+
141
+ /// Error during contract function preparation (ABI resolution, parameter encoding)
142
+ #[ error( "contract preparation failed: {0}" ) ]
143
+ PreparationFailed ( String ) ,
144
+
145
+ /// Error during multicall execution
146
+ #[ error( "multicall execution failed: {0}" ) ]
147
+ MulticallExecutionFailed ( String ) ,
148
+
149
+ /// Error during result decoding
150
+ #[ error( "result decoding failed: {0}" ) ]
151
+ ResultDecodingFailed ( String ) ,
152
+
153
+ /// Parameter validation error
154
+ #[ error( "parameter validation failed: {0}" ) ]
155
+ ParameterValidationFailed ( String ) ,
156
+
157
+ /// Function resolution error
158
+ #[ error( "function resolution failed: {0}" ) ]
159
+ FunctionResolutionFailed ( String ) ,
138
160
}
139
161
140
- #[ derive( Error , Debug , Serialize , Clone , Deserialize ) ]
162
+ #[ derive( Error , Debug , Serialize , Clone , Deserialize , JsonSchema ) ]
141
163
pub enum EngineError {
142
164
#[ error( "RPC error on chain {chain_id} at {rpc_url}: {message}" ) ]
143
165
RpcError {
@@ -175,6 +197,7 @@ pub enum EngineError {
175
197
#[ error( "Contract interaction error: {message}" ) ]
176
198
ContractInteractionError {
177
199
/// Contract address
200
+ #[ schemars( with = "Option<AddressDef>" ) ]
178
201
contract_address : Option < Address > ,
179
202
/// Chain ID
180
203
chain_id : u64 ,
@@ -202,6 +225,43 @@ impl From<InvalidHeaderValue> for EngineError {
202
225
}
203
226
}
204
227
228
+ impl EngineError {
229
+ pub fn contract_preparation_error (
230
+ contract_address : Option < Address > ,
231
+ chain_id : u64 ,
232
+ message : String ,
233
+ ) -> Self {
234
+ EngineError :: ContractInteractionError {
235
+ contract_address,
236
+ chain_id,
237
+ message : message. clone ( ) ,
238
+ kind : ContractInteractionErrorKind :: PreparationFailed ( message) ,
239
+ }
240
+ }
241
+
242
+ pub fn contract_multicall_error ( chain_id : u64 , message : String ) -> Self {
243
+ EngineError :: ContractInteractionError {
244
+ contract_address : None ,
245
+ chain_id,
246
+ message : message. clone ( ) ,
247
+ kind : ContractInteractionErrorKind :: MulticallExecutionFailed ( message) ,
248
+ }
249
+ }
250
+
251
+ pub fn contract_decoding_error (
252
+ contract_address : Option < Address > ,
253
+ chain_id : u64 ,
254
+ message : String ,
255
+ ) -> Self {
256
+ EngineError :: ContractInteractionError {
257
+ contract_address,
258
+ chain_id,
259
+ message : message. clone ( ) ,
260
+ kind : ContractInteractionErrorKind :: ResultDecodingFailed ( message) ,
261
+ }
262
+ }
263
+ }
264
+
205
265
pub trait AlloyRpcErrorToEngineError {
206
266
fn to_engine_error ( & self , chain : & impl Chain ) -> EngineError ;
207
267
fn to_engine_bundler_error ( & self , chain : & impl Chain ) -> EngineError ;
0 commit comments