@@ -14,7 +14,7 @@ pub enum AppRpcError {
1414pub enum LocalError {
1515 Decoder ( String ) ,
1616 Internal ,
17- Io ( String ) ,
17+ IO ( String ) ,
1818 Signing ( String ) ,
1919 Transport ( String ) ,
2020}
@@ -33,7 +33,7 @@ impl From<Web3Error> for AppRpcError {
3333 // Local Errors
3434 Web3Error :: Decoder ( error) => AppRpcError :: Local ( LocalError :: Decoder ( error) ) ,
3535 Web3Error :: Internal => AppRpcError :: Local ( LocalError :: Internal ) ,
36- Web3Error :: Io ( error) => AppRpcError :: Local ( LocalError :: Io ( error. to_string ( ) ) ) ,
36+ Web3Error :: Io ( error) => AppRpcError :: Local ( LocalError :: IO ( error. to_string ( ) ) ) ,
3737 Web3Error :: Signing ( error) => {
3838 // This variant cannot be tested due to import limitations.
3939 AppRpcError :: Local ( LocalError :: Signing ( error. to_string ( ) ) )
@@ -53,35 +53,44 @@ impl From<Web3Error> for AppRpcError {
5353 }
5454}
5555
56- #[ derive( Debug , Hash , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
56+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
5757pub enum AppRpcErrorKind {
58- // Local
58+ Local ( LocalErrorKind ) ,
59+ Remote ( RemoteErrorKind ) ,
60+ }
61+
62+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
63+ pub enum LocalErrorKind {
5964 Decoder ,
6065 Internal ,
6166 IO ,
6267 Signing ,
6368 Transport ,
69+ }
6470
65- // Remote
71+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
72+ pub enum RemoteErrorKind {
6673 InvalidResponse ,
67- ServerUnreachable ,
74+ Unreachable ,
6875 Web3RpcError ( i64 ) , // Keep only the stable error code
6976}
7077
7178impl From < & AppRpcError > for AppRpcErrorKind {
7279 fn from ( err : & AppRpcError ) -> Self {
7380 match err {
7481 AppRpcError :: Local ( local) => match local {
75- LocalError :: Decoder ( _) => Self :: Decoder ,
76- LocalError :: Internal => Self :: Internal ,
77- LocalError :: Io ( _) => Self :: IO ,
78- LocalError :: Signing ( _) => Self :: Signing ,
79- LocalError :: Transport ( _) => Self :: Transport ,
82+ LocalError :: Decoder ( _) => Self :: Local ( LocalErrorKind :: Decoder ) ,
83+ LocalError :: Internal => Self :: Local ( LocalErrorKind :: Internal ) ,
84+ LocalError :: IO ( _) => Self :: Local ( LocalErrorKind :: IO ) ,
85+ LocalError :: Signing ( _) => Self :: Local ( LocalErrorKind :: Signing ) ,
86+ LocalError :: Transport ( _) => Self :: Local ( LocalErrorKind :: Transport ) ,
8087 } ,
8188 AppRpcError :: Remote ( remote) => match remote {
82- RemoteError :: InvalidResponse ( _) => Self :: InvalidResponse ,
83- RemoteError :: Unreachable => Self :: ServerUnreachable ,
84- RemoteError :: Web3RpcError { code, .. } => Self :: Web3RpcError ( * code) ,
89+ RemoteError :: InvalidResponse ( _) => Self :: Remote ( RemoteErrorKind :: InvalidResponse ) ,
90+ RemoteError :: Unreachable => Self :: Remote ( RemoteErrorKind :: Unreachable ) ,
91+ RemoteError :: Web3RpcError { code, .. } => {
92+ Self :: Remote ( RemoteErrorKind :: Web3RpcError ( * code) )
93+ }
8594 } ,
8695 }
8796 }
@@ -90,7 +99,7 @@ impl From<&AppRpcError> for AppRpcErrorKind {
9099#[ cfg( test) ]
91100mod tests {
92101 use crate :: blockchain:: errors:: rpc_errors:: {
93- AppRpcError , AppRpcErrorKind , LocalError , RemoteError ,
102+ AppRpcError , AppRpcErrorKind , LocalError , LocalErrorKind , RemoteError , RemoteErrorKind ,
94103 } ;
95104 use web3:: error:: Error as Web3Error ;
96105
@@ -110,7 +119,7 @@ mod tests {
110119 std:: io:: ErrorKind :: Other ,
111120 "IO error"
112121 ) ) ) ,
113- AppRpcError :: Local ( LocalError :: Io ( "IO error" . to_string( ) ) )
122+ AppRpcError :: Local ( LocalError :: IO ( "IO error" . to_string( ) ) )
114123 ) ;
115124 assert_eq ! (
116125 AppRpcError :: from( Web3Error :: Transport ( "Transport error" . to_string( ) ) ) ,
@@ -145,69 +154,66 @@ mod tests {
145154 AppRpcErrorKind :: from( & AppRpcError :: Local ( LocalError :: Decoder (
146155 "Decoder error" . to_string( )
147156 ) ) ) ,
148- AppRpcErrorKind :: Decoder
157+ AppRpcErrorKind :: Local ( LocalErrorKind :: Decoder )
149158 ) ;
150159 assert_eq ! (
151160 AppRpcErrorKind :: from( & AppRpcError :: Local ( LocalError :: Internal ) ) ,
152- AppRpcErrorKind :: Internal
161+ AppRpcErrorKind :: Local ( LocalErrorKind :: Internal )
153162 ) ;
154163 assert_eq ! (
155- AppRpcErrorKind :: from( & AppRpcError :: Local ( LocalError :: Io ( "IO error" . to_string( ) ) ) ) ,
156- AppRpcErrorKind :: IO
164+ AppRpcErrorKind :: from( & AppRpcError :: Local ( LocalError :: IO ( "IO error" . to_string( ) ) ) ) ,
165+ AppRpcErrorKind :: Local ( LocalErrorKind :: IO )
157166 ) ;
158167 assert_eq ! (
159168 AppRpcErrorKind :: from( & AppRpcError :: Local ( LocalError :: Signing (
160169 "Signing error" . to_string( )
161170 ) ) ) ,
162- AppRpcErrorKind :: Signing
171+ AppRpcErrorKind :: Local ( LocalErrorKind :: Signing )
163172 ) ;
164173 assert_eq ! (
165174 AppRpcErrorKind :: from( & AppRpcError :: Local ( LocalError :: Transport (
166175 "Transport error" . to_string( )
167176 ) ) ) ,
168- AppRpcErrorKind :: Transport
177+ AppRpcErrorKind :: Local ( LocalErrorKind :: Transport )
169178 ) ;
170179 assert_eq ! (
171180 AppRpcErrorKind :: from( & AppRpcError :: Remote ( RemoteError :: InvalidResponse (
172181 "Invalid response" . to_string( )
173182 ) ) ) ,
174- AppRpcErrorKind :: InvalidResponse
183+ AppRpcErrorKind :: Remote ( RemoteErrorKind :: InvalidResponse )
175184 ) ;
176185 assert_eq ! (
177186 AppRpcErrorKind :: from( & AppRpcError :: Remote ( RemoteError :: Unreachable ) ) ,
178- AppRpcErrorKind :: ServerUnreachable
187+ AppRpcErrorKind :: Remote ( RemoteErrorKind :: Unreachable )
179188 ) ;
180189 assert_eq ! (
181190 AppRpcErrorKind :: from( & AppRpcError :: Remote ( RemoteError :: Web3RpcError {
182191 code: 55 ,
183192 message: "Booga" . to_string( )
184193 } ) ) ,
185- AppRpcErrorKind :: Web3RpcError ( 55 )
194+ AppRpcErrorKind :: Remote ( RemoteErrorKind :: Web3RpcError ( 55 ) )
186195 ) ;
187196 }
188197
189198 #[ test]
190199 fn app_rpc_error_kind_serialization_deserialization ( ) {
191200 let errors = vec ! [
192- // Local Errors
193- AppRpcErrorKind :: Decoder ,
194- AppRpcErrorKind :: Internal ,
195- AppRpcErrorKind :: IO ,
196- AppRpcErrorKind :: Signing ,
197- AppRpcErrorKind :: Transport ,
198- // Remote Errors
199- AppRpcErrorKind :: InvalidResponse ,
200- AppRpcErrorKind :: ServerUnreachable ,
201- AppRpcErrorKind :: Web3RpcError ( 42 ) ,
201+ AppRpcErrorKind :: Local ( LocalErrorKind :: Decoder ) ,
202+ AppRpcErrorKind :: Local ( LocalErrorKind :: Internal ) ,
203+ AppRpcErrorKind :: Local ( LocalErrorKind :: IO ) ,
204+ AppRpcErrorKind :: Local ( LocalErrorKind :: Signing ) ,
205+ AppRpcErrorKind :: Local ( LocalErrorKind :: Transport ) ,
206+ AppRpcErrorKind :: Remote ( RemoteErrorKind :: InvalidResponse ) ,
207+ AppRpcErrorKind :: Remote ( RemoteErrorKind :: Unreachable ) ,
208+ AppRpcErrorKind :: Remote ( RemoteErrorKind :: Web3RpcError ( 42 ) ) ,
202209 ] ;
203210
204211 errors. into_iter ( ) . for_each ( |error| {
205212 let serialized = serde_json:: to_string ( & error) . unwrap ( ) ;
206213 let deserialized: AppRpcErrorKind = serde_json:: from_str ( & serialized) . unwrap ( ) ;
207214 assert_eq ! (
208215 error, deserialized,
209- "Failed serde attempt for {:?} that should look \
210- like {:?}",
216+ "Failed serde attempt for {:?} that should look like {:?}" ,
211217 deserialized, error
212218 ) ;
213219 } ) ;
0 commit comments