@@ -508,7 +508,8 @@ pub mod tests {
508508 use super :: * ;
509509
510510 use std:: time:: { Duration , Instant } ;
511- use std:: io:: { Error , ErrorKind } ;
511+ use failure:: Error ;
512+ use std:: io:: { Error as IoError , ErrorKind as IoErrorKind } ;
512513
513514 use tokio:: net:: TcpListener ;
514515 use tokio:: timer:: Interval ;
@@ -542,9 +543,8 @@ pub mod tests {
542543 pk : gen_keypair ( ) . 0 ,
543544 } ) ;
544545
545- let res = client. handle_packet ( route_request) . wait ( ) ;
546- assert ! ( res. is_err( ) ) ;
547- assert_eq ! ( * res. err( ) . unwrap( ) . kind( ) , HandlePacketErrorKind :: MustNotSend ) ;
546+ let error = client. handle_packet ( route_request) . wait ( ) . err ( ) . unwrap ( ) ;
547+ assert_eq ! ( * error. kind( ) , HandlePacketErrorKind :: MustNotSend ) ;
548548 }
549549
550550 #[ test]
@@ -603,9 +603,8 @@ pub mod tests {
603603 pk : gen_keypair ( ) . 0 ,
604604 } ) ;
605605
606- let res = client. handle_packet ( route_response) . wait ( ) ;
607- assert ! ( res. is_err( ) ) ;
608- assert_eq ! ( * res. err( ) . unwrap( ) . kind( ) , HandlePacketErrorKind :: UnexpectedRouteResponse ) ;
606+ let error = client. handle_packet ( route_response) . wait ( ) . err ( ) . unwrap ( ) ;
607+ assert_eq ! ( * error. kind( ) , HandlePacketErrorKind :: UnexpectedRouteResponse ) ;
609608
610609 assert ! ( client. links. read( ) . by_id( index) . is_none( ) ) ;
611610 }
@@ -619,9 +618,8 @@ pub mod tests {
619618 pk : gen_keypair ( ) . 0 ,
620619 } ) ;
621620
622- let res = client. handle_packet ( route_response) . wait ( ) ;
623- assert ! ( res. is_err( ) ) ;
624- assert_eq ! ( * res. err( ) . unwrap( ) . kind( ) , HandlePacketErrorKind :: InvalidConnectionId ) ;
621+ let error = client. handle_packet ( route_response) . wait ( ) . err ( ) . unwrap ( ) ;
622+ assert_eq ! ( * error. kind( ) , HandlePacketErrorKind :: InvalidConnectionId ) ;
625623 }
626624
627625 #[ test]
@@ -654,9 +652,8 @@ pub mod tests {
654652 connection_id : ConnectionId :: from_index ( index) ,
655653 } ) ;
656654
657- let res = client. handle_packet ( connect_notification) . wait ( ) ;
658- assert ! ( res. is_err( ) ) ;
659- assert_eq ! ( * res. err( ) . unwrap( ) . kind( ) , HandlePacketErrorKind :: AlreadyLinked ) ;
655+ let error = client. handle_packet ( connect_notification) . wait ( ) . err ( ) . unwrap ( ) ;
656+ assert_eq ! ( * error. kind( ) , HandlePacketErrorKind :: AlreadyLinked ) ;
660657
661658 assert ! ( client. links. read( ) . by_id( index) . is_none( ) ) ;
662659 }
@@ -669,9 +666,8 @@ pub mod tests {
669666 connection_id : ConnectionId :: zero ( ) ,
670667 } ) ;
671668
672- let res = client. handle_packet ( connect_notification) . wait ( ) ;
673- assert ! ( res. is_err( ) ) ;
674- assert_eq ! ( * res. err( ) . unwrap( ) . kind( ) , HandlePacketErrorKind :: InvalidConnectionId ) ;
669+ let error = client. handle_packet ( connect_notification) . wait ( ) . err ( ) . unwrap ( ) ;
670+ assert_eq ! ( * error. kind( ) , HandlePacketErrorKind :: InvalidConnectionId ) ;
675671 }
676672
677673 #[ test]
@@ -705,9 +701,8 @@ pub mod tests {
705701 connection_id : ConnectionId :: from_index ( index) ,
706702 } ) ;
707703
708- let res = client. handle_packet ( disconnect_notification) . wait ( ) ;
709- assert ! ( res. is_err( ) ) ;
710- assert_eq ! ( * res. err( ) . unwrap( ) . kind( ) , HandlePacketErrorKind :: AlreadyLinked ) ;
704+ let error = client. handle_packet ( disconnect_notification) . wait ( ) . err ( ) . unwrap ( ) ;
705+ assert_eq ! ( * error. kind( ) , HandlePacketErrorKind :: AlreadyLinked ) ;
711706
712707 assert ! ( client. links. read( ) . by_id( index) . is_none( ) ) ;
713708 }
@@ -720,9 +715,8 @@ pub mod tests {
720715 connection_id : ConnectionId :: zero ( ) ,
721716 } ) ;
722717
723- let res = client. handle_packet ( disconnect_notification) . wait ( ) ;
724- assert ! ( res. is_err( ) ) ;
725- assert_eq ! ( * res. err( ) . unwrap( ) . kind( ) , HandlePacketErrorKind :: InvalidConnectionId ) ;
718+ let error = client. handle_packet ( disconnect_notification) . wait ( ) . err ( ) . unwrap ( ) ;
719+ assert_eq ! ( * error. kind( ) , HandlePacketErrorKind :: InvalidConnectionId ) ;
726720 }
727721
728722 #[ test]
@@ -762,9 +756,8 @@ pub mod tests {
762756 data : vec ! [ 42 ; 123 ] ,
763757 } ) ;
764758
765- let res = client. handle_packet ( oob_send) . wait ( ) ;
766- assert ! ( res. is_err( ) ) ;
767- assert_eq ! ( * res. err( ) . unwrap( ) . kind( ) , HandlePacketErrorKind :: MustNotSend ) ;
759+ let error = client. handle_packet ( oob_send) . wait ( ) . err ( ) . unwrap ( ) ;
760+ assert_eq ! ( * error. kind( ) , HandlePacketErrorKind :: MustNotSend ) ;
768761 }
769762
770763 #[ test]
@@ -829,9 +822,8 @@ pub mod tests {
829822 } ) ,
830823 } ) ;
831824
832- let res = client. handle_packet ( data_packet) . wait ( ) ;
833- assert ! ( res. is_err( ) ) ;
834- assert_eq ! ( * res. err( ) . unwrap( ) . kind( ) , HandlePacketErrorKind :: AlreadyLinked ) ;
825+ let error = client. handle_packet ( data_packet) . wait ( ) . err ( ) . unwrap ( ) ;
826+ assert_eq ! ( * error. kind( ) , HandlePacketErrorKind :: AlreadyLinked ) ;
835827
836828 // Necessary to drop tx so that rx.collect() can be finished
837829 drop ( client) ;
@@ -851,9 +843,8 @@ pub mod tests {
851843 } ) ,
852844 } ) ;
853845
854- let res = client. handle_packet ( data_packet) . wait ( ) ;
855- assert ! ( res. is_err( ) ) ;
856- assert_eq ! ( * res. err( ) . unwrap( ) . kind( ) , HandlePacketErrorKind :: InvalidConnectionId ) ;
846+ let error = client. handle_packet ( data_packet) . wait ( ) . err ( ) . unwrap ( ) ;
847+ assert_eq ! ( * error. kind( ) , HandlePacketErrorKind :: InvalidConnectionId ) ;
857848
858849 // Necessary to drop tx so that rx.collect() can be finished
859850 drop ( client) ;
@@ -876,9 +867,8 @@ pub mod tests {
876867 payload : vec ! [ 42 ; 123 ] ,
877868 } ) ;
878869
879- let res = client. handle_packet ( onion_request) . wait ( ) ;
880- assert ! ( res. is_err( ) ) ;
881- assert_eq ! ( * res. err( ) . unwrap( ) . kind( ) , HandlePacketErrorKind :: MustNotSend ) ;
870+ let error = client. handle_packet ( onion_request) . wait ( ) . err ( ) . unwrap ( ) ;
871+ assert_eq ! ( * error. kind( ) , HandlePacketErrorKind :: MustNotSend ) ;
882872 }
883873
884874 #[ test]
@@ -935,9 +925,8 @@ pub mod tests {
935925 payload : vec ! [ 42 ; 123 ] ,
936926 } ) ;
937927
938- let res = client. send_data ( destination_pk, data. clone ( ) ) . wait ( ) ;
939- assert ! ( res. is_err( ) ) ;
940- assert_eq ! ( * res. err( ) . unwrap( ) . kind( ) , SendPacketErrorKind :: NotLinked ) ;
928+ let error = client. send_data ( destination_pk, data. clone ( ) ) . wait ( ) . err ( ) . unwrap ( ) ;
929+ assert_eq ! ( * error. kind( ) , SendPacketErrorKind :: NotLinked ) ;
941930
942931 // Necessary to drop tx so that rx.collect() can be finished
943932 drop ( client) ;
@@ -958,9 +947,8 @@ pub mod tests {
958947 let connection_id = 42 ;
959948 client. links . write ( ) . insert_by_id ( & destination_pk, connection_id - 16 ) ;
960949
961- let res = client. send_data ( destination_pk, data. clone ( ) ) . wait ( ) ;
962- assert ! ( res. is_err( ) ) ;
963- assert_eq ! ( * res. err( ) . unwrap( ) . kind( ) , SendPacketErrorKind :: NotOnline ) ;
950+ let error = client. send_data ( destination_pk, data. clone ( ) ) . wait ( ) . err ( ) . unwrap ( ) ;
951+ assert_eq ! ( * error. kind( ) , SendPacketErrorKind :: NotOnline ) ;
964952
965953 // Necessary to drop tx so that rx.collect() can be finished
966954 drop ( client) ;
@@ -1050,9 +1038,8 @@ pub mod tests {
10501038
10511039 let ( connection_pk, _connection_sk) = gen_keypair ( ) ;
10521040
1053- let res = client. remove_connection ( connection_pk) . wait ( ) ;
1054- assert ! ( res. is_err( ) ) ;
1055- assert_eq ! ( * res. err( ) . unwrap( ) . kind( ) , SendPacketErrorKind :: NoSuchConnection ) ;
1041+ let error = client. remove_connection ( connection_pk) . wait ( ) . err ( ) . unwrap ( ) ;
1042+ assert_eq ! ( * error. kind( ) , SendPacketErrorKind :: NoSuchConnection ) ;
10561043 }
10571044
10581045 #[ test]
@@ -1144,11 +1131,11 @@ pub mod tests {
11441131 // waits until the relay becomes connected
11451132 fn on_connected ( client : Client ) -> impl Future < Item = ( ) , Error = Error > + Send {
11461133 Interval :: new ( Instant :: now ( ) , Duration :: from_millis ( 10 ) )
1147- . map_err ( |e| Error :: new ( ErrorKind :: Other , e ) )
1134+ . map_err ( Error :: from )
11481135 . skip_while ( move |_| match * client. status . read ( ) {
11491136 ClientStatus :: Connecting => future:: ok ( true ) ,
11501137 ClientStatus :: Connected ( _) => future:: ok ( false ) ,
1151- ref other => future:: err ( Error :: new ( ErrorKind :: Other , format ! ( "Invalid status: {:?}" , other) ) ) ,
1138+ ref other => future:: err ( Error :: from ( IoError :: new ( IoErrorKind :: Other , format ! ( "Invalid status: {:?}" , other) ) ) ) ,
11521139 } )
11531140 . into_future ( )
11541141 . map ( |_| ( ) )
@@ -1158,7 +1145,7 @@ pub mod tests {
11581145 // waits until link with PublicKey becomes online
11591146 fn on_online ( client : Client , pk : PublicKey ) -> impl Future < Item = ( ) , Error = Error > + Send {
11601147 Interval :: new ( Instant :: now ( ) , Duration :: from_millis ( 10 ) )
1161- . map_err ( |e| Error :: new ( ErrorKind :: Other , e ) )
1148+ . map_err ( Error :: from )
11621149 . skip_while ( move |_| {
11631150 let links = client. links . read ( ) ;
11641151 if let Some ( index) = links. id_by_pk ( & pk) {
@@ -1183,7 +1170,7 @@ pub mod tests {
11831170 let server = Server :: new ( ) ;
11841171 let stats = Stats :: new ( ) ;
11851172 let server_future = server. run ( listener, server_sk, stats, 2 )
1186- . map_err ( |e| Error :: new ( ErrorKind :: Other , e . compat ( ) ) ) ;
1173+ . map_err ( Error :: from ) ;
11871174
11881175 // run first client
11891176 let ( client_pk_1, client_sk_1) = gen_keypair ( ) ;
@@ -1192,7 +1179,7 @@ pub mod tests {
11921179 // connection attempts should be set to 0 after successful connection
11931180 set_connection_attempts ( & client_1, 3 ) ;
11941181 let client_future_1 = client_1. clone ( ) . spawn ( client_sk_1, client_pk_1)
1195- . map_err ( |e| Error :: new ( ErrorKind :: Other , e . compat ( ) ) ) ;
1182+ . map_err ( Error :: from ) ;
11961183
11971184 // run second client
11981185 let ( client_pk_2, client_sk_2) = gen_keypair ( ) ;
@@ -1201,11 +1188,11 @@ pub mod tests {
12011188 // connection attempts should be set to 0 after successful connection
12021189 set_connection_attempts ( & client_2, 3 ) ;
12031190 let client_future_2 = client_2. clone ( ) . spawn ( client_sk_2, client_pk_2)
1204- . map_err ( |e| Error :: new ( ErrorKind :: Other , e . compat ( ) ) ) ;
1191+ . map_err ( Error :: from ) ;
12051192
12061193 // add connection immediately
12071194 let connection_future = client_2. add_connection ( client_pk_1)
1208- . map_err ( |e| Error :: new ( ErrorKind :: Other , e . compat ( ) ) ) ;
1195+ . map_err ( Error :: from ) ;
12091196
12101197 // wait until connections are established
12111198 let client_1_c = client_1. clone ( ) ;
@@ -1217,7 +1204,7 @@ pub mod tests {
12171204 assert_eq ! ( client_2_c. connection_attempts( ) , 0 ) ;
12181205 // add connection when relay is connected
12191206 client_1_c. add_connection ( client_pk_2)
1220- . map_err ( |e| Error :: new ( ErrorKind :: Other , e . compat ( ) ) )
1207+ . map_err ( Error :: from )
12211208 } ) ;
12221209
12231210 let data_1 = DataPayload :: CryptoData ( CryptoData {
@@ -1237,9 +1224,9 @@ pub mod tests {
12371224 let on_online_future = on_online ( client_1. clone ( ) , client_pk_2) . join ( on_online ( client_2. clone ( ) , client_pk_1) )
12381225 // and then send data packets to each other
12391226 . and_then ( move |_| client_1_c. send_data ( client_pk_2, data_1_c)
1240- . map_err ( |e| Error :: new ( ErrorKind :: Other , e . compat ( ) ) ) )
1227+ . map_err ( Error :: from ) )
12411228 . and_then ( move |_| client_2_c. send_data ( client_pk_1, data_2_c)
1242- . map_err ( |e| Error :: new ( ErrorKind :: Other , e . compat ( ) ) ) )
1229+ . map_err ( Error :: from ) )
12431230 // and then get them
12441231 . and_then ( move |_| incoming_rx_1. map_err ( |( ) | unreachable ! ( "rx can't fail" ) ) . into_future ( ) . map ( move |( packet, _) | {
12451232 let ( relay_pk, packet) = packet. unwrap ( ) ;
@@ -1288,15 +1275,15 @@ pub mod tests {
12881275 let server = Server :: new ( ) ;
12891276 let stats = Stats :: new ( ) ;
12901277 let server_future = server. run ( listener, server_sk, stats, 2 )
1291- . map_err ( |e| Error :: new ( ErrorKind :: Other , e . compat ( ) ) ) ;
1278+ . map_err ( Error :: from ) ;
12921279
12931280 // run a client with invalid server's pk
12941281 let ( client_pk_1, client_sk_1) = gen_keypair ( ) ;
12951282 let ( invalid_server_pk, _invalid_server_sk) = gen_keypair ( ) ;
12961283 let ( incoming_tx_1, _incoming_rx_1) = mpsc:: unbounded ( ) ;
12971284 let client = Client :: new ( invalid_server_pk, addr, incoming_tx_1) ;
12981285 let client_future = client. clone ( ) . spawn ( client_sk_1, client_pk_1)
1299- . map_err ( |e| Error :: new ( ErrorKind :: Other , e . compat ( ) ) ) ;
1286+ . map_err ( Error :: from ) ;
13001287
13011288 let future = server_future
13021289 . select ( client_future)
0 commit comments