1
- use anyhow:: { Context , Error } ;
1
+ use anyhow:: Context ;
2
2
use std:: net:: SocketAddr ;
3
3
use std:: sync:: Arc ;
4
4
use tokio:: {
@@ -23,7 +23,7 @@ pub(crate) struct ChaosProxy {
23
23
}
24
24
25
25
impl ChaosProxy {
26
- pub ( crate ) fn new ( backend_address : SocketAddr ) -> Result < Arc < Self > , Error > {
26
+ pub ( crate ) fn new ( backend_address : SocketAddr ) -> anyhow :: Result < Arc < Self > > {
27
27
let runtime = Runtime :: new ( ) . expect ( "failed to create Tokio runtime" ) ;
28
28
let listener = runtime. block_on ( TcpListener :: bind ( "127.0.0.1:0" ) ) ?;
29
29
@@ -50,7 +50,7 @@ impl ChaosProxy {
50
50
Ok ( instance)
51
51
}
52
52
53
- pub ( crate ) fn proxy_database_url ( url : & str ) -> Result < ( Arc < Self > , String ) , Error > {
53
+ pub ( crate ) fn proxy_database_url ( url : & str ) -> anyhow :: Result < ( Arc < Self > , String ) > {
54
54
let mut db_url = Url :: parse ( url) . context ( "failed to parse database url" ) ?;
55
55
let backend_addr = db_url
56
56
. socket_addrs ( || Some ( 5432 ) )
@@ -77,7 +77,7 @@ impl ChaosProxy {
77
77
. context ( "Failed to send the restore_networking message" )
78
78
}
79
79
80
- async fn server_loop ( & self , initial_listener : TcpListener ) -> Result < ( ) , Error > {
80
+ async fn server_loop ( & self , initial_listener : TcpListener ) -> anyhow :: Result < ( ) > {
81
81
let mut listener = Some ( initial_listener) ;
82
82
83
83
let mut break_networking_recv = self . break_networking_send . subscribe ( ) ;
@@ -104,7 +104,7 @@ impl ChaosProxy {
104
104
}
105
105
}
106
106
107
- async fn accept_connection ( & self , accepted : TcpStream ) -> Result < ( ) , Error > {
107
+ async fn accept_connection ( & self , accepted : TcpStream ) -> anyhow :: Result < ( ) > {
108
108
let ( client_read, client_write) = accepted. into_split ( ) ;
109
109
let ( backend_read, backend_write) = TcpStream :: connect ( & self . backend_address )
110
110
. await ?
@@ -132,7 +132,7 @@ async fn proxy_data(
132
132
break_networking_send : Sender < ( ) > ,
133
133
mut from : OwnedReadHalf ,
134
134
mut to : OwnedWriteHalf ,
135
- ) -> Result < ( ) , Error > {
135
+ ) -> anyhow :: Result < ( ) > {
136
136
let mut break_connections_recv = break_networking_send. subscribe ( ) ;
137
137
let mut buf = [ 0 ; 1024 ] ;
138
138
0 commit comments