@@ -241,11 +241,11 @@ pub mod pallet {
241241
242242 Ok ( ( ) )
243243 }
244- _ => Err ( Error :: < T > :: MissingExpectedField . into ( ) ) ,
244+ _ => emit_missing_expected_field_error :: < T > ( ) ,
245245 }
246246 } )
247- . for_each ( emit_for_error :: < T > ) ;
248- Ok ( ( ) )
247+ . collect :: < Result < Vec < _ > , _ > > ( )
248+ . map ( |_| ( ) )
249249 }
250250
251251 /// Process a Nominate SystemRequest
@@ -272,9 +272,10 @@ pub mod pallet {
272272 errors
273273 ) ;
274274
275- errors
276- . into_iter ( )
277- . for_each ( |e| emit_for_error :: < T > ( Result :: < ( ) , _ > :: Err ( e) ) ) ;
275+ for error in errors. iter ( ) . copied ( ) {
276+ emit_error :: < T > ( error) ;
277+ }
278+ Err ( * errors. first ( ) . expect ( "There is at least one error" ) ) ?;
278279 }
279280
280281 if nominations. is_empty ( ) {
@@ -289,12 +290,11 @@ pub mod pallet {
289290 pallet_staking:: Pallet :: < T > :: nominate ( nominator_signer, nominations) ?;
290291 Ok ( ( ) )
291292 }
292- _ => Err ( Error :: < T > :: MissingExpectedField . into ( ) ) ,
293+ _ => emit_missing_expected_field_error :: < T > ( ) ,
293294 }
294295 } )
295- . for_each ( emit_for_error :: < T > ) ;
296-
297- Ok ( ( ) )
296+ . collect :: < Result < Vec < _ > , _ > > ( )
297+ . map ( |_| ( ) )
298298 }
299299
300300 /// Processes the actual withdrawal once the Unstaked event is emitted from the Ethereum
@@ -325,12 +325,11 @@ pub mod pallet {
325325
326326 Ok ( ( ) )
327327 }
328- _ => Err ( Error :: < T > :: MissingExpectedField . into ( ) ) ,
328+ _ => emit_missing_expected_field_error :: < T > ( ) ,
329329 }
330330 } )
331- . for_each ( emit_for_error :: < T > ) ;
332-
333- Ok ( ( ) )
331+ . collect :: < Result < Vec < _ > , _ > > ( )
332+ . map ( |_| ( ) )
334333 }
335334
336335 /// Processes an unstake claimed event and updates chain state appropriately
@@ -383,11 +382,11 @@ pub mod pallet {
383382
384383 Ok ( ( ) )
385384 }
386- _ => Err ( Error :: < T > :: MissingExpectedField . into ( ) ) ,
385+ _ => emit_missing_expected_field_error :: < T > ( ) ,
387386 }
388387 } )
389- . for_each ( emit_for_error :: < T > ) ;
390- Ok ( ( ) )
388+ . collect :: < Result < Vec < _ > , _ > > ( )
389+ . map ( |_| ( ) )
391390 }
392391
393392 /// Parse a system request to initiate unstaking
@@ -420,12 +419,11 @@ pub mod pallet {
420419
421420 Ok ( ( ) )
422421 }
423- _ => Err ( Error :: < T > :: MissingExpectedField . into ( ) ) ,
422+ _ => emit_missing_expected_field_error :: < T > ( ) ,
424423 }
425424 } )
426- . for_each ( emit_for_error :: < T > ) ;
427-
428- Ok ( ( ) )
425+ . collect :: < Result < Vec < _ > , _ > > ( )
426+ . map ( |_| ( ) )
429427 }
430428
431429 /// Process a request to cancel unstakng
@@ -448,18 +446,21 @@ pub mod pallet {
448446 . map_err ( |e| e. error ) ?;
449447 Ok ( ( ) )
450448 }
451- _ => Err ( Error :: < T > :: MissingExpectedField . into ( ) ) ,
449+ _ => emit_missing_expected_field_error :: < T > ( ) ,
452450 }
453451 } )
454- . for_each ( emit_for_error :: < T > ) ;
455- Ok ( ( ) )
452+ . collect :: < Result < Vec < _ > , _ > > ( )
453+ . map ( |_| ( ) )
456454 }
457455
458- fn emit_for_error < T : Config > ( r : DispatchResult ) {
459- if let Err ( error) = r {
460- // Emit an event for any errors
461- Pallet :: < T > :: deposit_event ( Event :: < T > :: MessageProcessingError { error } ) ;
462- }
456+ fn emit_error < T : Config > ( error : DispatchError ) {
457+ Pallet :: < T > :: deposit_event ( Event :: < T > :: MessageProcessingError { error } ) ;
458+ }
459+
460+ fn emit_missing_expected_field_error < T : Config > ( ) -> DispatchResult {
461+ let error = Error :: < T > :: MissingExpectedField . into ( ) ;
462+ emit_error :: < T > ( error) ;
463+ Err ( error)
463464 }
464465
465466 #[ pallet:: storage]
@@ -502,12 +503,11 @@ pub mod pallet {
502503 messages:: handle_message :: < T > ( eth_sender, body. to_vec ( ) ) ?;
503504 Ok ( ( ) )
504505 }
505- _ => Err ( Error :: < T > :: MissingExpectedField . into ( ) ) ,
506+ _ => emit_missing_expected_field_error :: < T > ( ) ,
506507 }
507508 } )
508- . for_each ( emit_for_error :: < T > ) ;
509-
510- Ok ( ( ) )
509+ . collect :: < Result < Vec < _ > , _ > > ( )
510+ . map ( |_| ( ) )
511511 }
512512
513513 /// Process a funded message received from our EVM contract
@@ -541,12 +541,11 @@ pub mod pallet {
541541 ) ?;
542542 Ok ( ( ) )
543543 }
544- _ => Err ( Error :: < T > :: MissingExpectedField . into ( ) ) ,
544+ _ => emit_missing_expected_field_error :: < T > ( ) ,
545545 }
546546 } )
547- . for_each ( emit_for_error :: < T > ) ;
548-
549- Ok ( ( ) )
547+ . collect :: < Result < Vec < _ > , _ > > ( )
548+ . map ( |_| ( ) )
550549 }
551550
552551 /// A custom offence handler that chills validators when they offend
0 commit comments