1+ use crate :: defs:: AddressDef ;
12use alloy:: {
23 primitives:: Address ,
34 transports:: {
45 RpcError as AlloyRpcError , TransportErrorKind , http:: reqwest:: header:: InvalidHeaderValue ,
56 } ,
67} ;
8+ use schemars:: JsonSchema ;
79use serde:: { Deserialize , Serialize } ;
810use thirdweb_core:: error:: ThirdwebError ;
911use thiserror:: Error ;
1012use twmq:: error:: TwmqError ;
1113
1214use crate :: chain:: Chain ;
1315
14- #[ derive( Debug , Error , Clone , Serialize , Deserialize ) ]
16+ #[ derive( Debug , Error , Clone , Serialize , Deserialize , JsonSchema ) ]
1517pub enum RpcErrorKind {
1618 /// Server returned an error response.
1719 #[ error( "server returned an error response: {0}" ) ]
@@ -56,7 +58,7 @@ pub enum RpcErrorKind {
5658 OtherTransportError ( String ) ,
5759}
5860
59- #[ derive( Debug , Serialize , Deserialize , Clone ) ]
61+ #[ derive( Debug , Serialize , Deserialize , Clone , JsonSchema ) ]
6062pub struct RpcErrorResponse {
6163 /// The error code.
6264 pub code : i64 ,
@@ -80,7 +82,7 @@ impl RpcErrorResponse {
8082 }
8183}
8284
83- #[ derive( Debug , Serialize , Deserialize ) ]
85+ #[ derive( Debug , Serialize , Deserialize , JsonSchema ) ]
8486pub struct RpcErrorInfo {
8587 /// The chain ID where the error occurred
8688 pub chain_id : u64 ,
@@ -97,7 +99,7 @@ pub struct RpcErrorInfo {
9799}
98100
99101/// A serializable contract interaction error type
100- #[ derive( Debug , Error , Serialize , Deserialize , Clone ) ]
102+ #[ derive( Debug , Error , Serialize , Deserialize , Clone , JsonSchema ) ]
101103pub enum ContractInteractionErrorKind {
102104 /// Unknown function referenced.
103105 #[ error( "unknown function: function {0} does not exist" ) ]
@@ -135,9 +137,29 @@ pub enum ContractInteractionErrorKind {
135137 /// An error occured while waiting for a pending transaction.
136138 #[ error( "pending transaction error: {0}" ) ]
137139 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 ) ,
138160}
139161
140- #[ derive( Error , Debug , Serialize , Clone , Deserialize ) ]
162+ #[ derive( Error , Debug , Serialize , Clone , Deserialize , JsonSchema ) ]
141163pub enum EngineError {
142164 #[ error( "RPC error on chain {chain_id} at {rpc_url}: {message}" ) ]
143165 RpcError {
@@ -175,6 +197,7 @@ pub enum EngineError {
175197 #[ error( "Contract interaction error: {message}" ) ]
176198 ContractInteractionError {
177199 /// Contract address
200+ #[ schemars( with = "Option<AddressDef>" ) ]
178201 contract_address : Option < Address > ,
179202 /// Chain ID
180203 chain_id : u64 ,
@@ -202,6 +225,43 @@ impl From<InvalidHeaderValue> for EngineError {
202225 }
203226}
204227
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+
205265pub trait AlloyRpcErrorToEngineError {
206266 fn to_engine_error ( & self , chain : & impl Chain ) -> EngineError ;
207267 fn to_engine_bundler_error ( & self , chain : & impl Chain ) -> EngineError ;
0 commit comments