@@ -17,7 +17,6 @@ use crate::allocator::zero_copy::initialize::initialize_networking;
1717use crate :: logging:: { CommunicationSetup , CommunicationEvent } ;
1818use logging_core:: Logger ;
1919use std:: fmt:: { Debug , Formatter } ;
20- use anyhow:: { bail, Context } ;
2120
2221
2322/// Possible configurations for the communication infrastructure.
@@ -90,23 +89,23 @@ impl Config {
9089 /// This method is only available if the `getopts` feature is enabled, which
9190 /// it is by default.
9291 #[ cfg( feature = "getopts" ) ]
93- pub fn from_matches ( matches : & getopts:: Matches ) -> crate :: Result < Config > {
94- let threads = matches. opt_get_default ( "w" , 1_usize ) ?;
95- let process = matches. opt_get_default ( "p" , 0_usize ) ?;
96- let processes = matches. opt_get_default ( "n" , 1_usize ) ?;
92+ pub fn from_matches ( matches : & getopts:: Matches ) -> Result < Config , String > {
93+ let threads = matches. opt_get_default ( "w" , 1_usize ) . map_err ( |e| e . to_string ( ) ) ?;
94+ let process = matches. opt_get_default ( "p" , 0_usize ) . map_err ( |e| e . to_string ( ) ) ?;
95+ let processes = matches. opt_get_default ( "n" , 1_usize ) . map_err ( |e| e . to_string ( ) ) ?;
9796 let report = matches. opt_present ( "report" ) ;
9897 let zerocopy = matches. opt_present ( "zerocopy" ) ;
9998
10099 if processes > 1 {
101100 let mut addresses = Vec :: new ( ) ;
102101 if let Some ( hosts) = matches. opt_str ( "h" ) {
103- let file = :: std:: fs:: File :: open ( hosts. clone ( ) ) ?;
102+ let file = :: std:: fs:: File :: open ( hosts. clone ( ) ) . map_err ( |e| e . to_string ( ) ) ?;
104103 let reader = :: std:: io:: BufReader :: new ( file) ;
105104 for line in reader. lines ( ) . take ( processes) {
106- addresses. push ( line?) ;
105+ addresses. push ( line. map_err ( |e| e . to_string ( ) ) ?) ;
107106 }
108107 if addresses. len ( ) < processes {
109- bail ! ( "could only read {} addresses from {hosts }, but -n: {processes }" , addresses. len( ) ) ;
108+ return Err ( format ! ( "could only read {} addresses from {}, but -n: {}" , addresses. len( ) , hosts , processes ) ) ;
110109 }
111110 }
112111 else {
@@ -141,10 +140,10 @@ impl Config {
141140 /// This method is only available if the `getopts` feature is enabled, which
142141 /// it is by default.
143142 #[ cfg( feature = "getopts" ) ]
144- pub fn from_args < I : Iterator < Item =String > > ( args : I ) -> crate :: Result < Config > {
143+ pub fn from_args < I : Iterator < Item =String > > ( args : I ) -> Result < Config , String > {
145144 let mut opts = getopts:: Options :: new ( ) ;
146145 Config :: install_options ( & mut opts) ;
147- let matches = opts. parse ( args) ?;
146+ let matches = opts. parse ( args) . map_err ( |e| e . to_string ( ) ) ?;
148147 Config :: from_matches ( & matches)
149148 }
150149
@@ -161,8 +160,7 @@ impl Config {
161160 Ok ( ( ProcessBuilder :: new_vector ( threads) . into_iter ( ) . map ( |x| GenericBuilder :: ProcessBinary ( x) ) . collect ( ) , Box :: new ( ( ) ) ) )
162161 } ,
163162 Config :: Cluster { threads, process, addresses, report, log_fn } => {
164- let ( stuff, guard) = initialize_networking ( addresses, process, threads, report, log_fn)
165- . context ( "initializing network" ) ?;
163+ let ( stuff, guard) = initialize_networking ( addresses, process, threads, report, log_fn) ?;
166164 Ok ( ( stuff. into_iter ( ) . map ( |x| GenericBuilder :: ZeroCopy ( x) ) . collect ( ) , Box :: new ( guard) ) )
167165 } ,
168166 }
@@ -337,10 +335,10 @@ impl<T:Send+'static> WorkerGuards<T> {
337335 }
338336
339337 /// Waits on the worker threads and returns the results they produce.
340- pub fn join ( mut self ) -> Vec < crate :: Result < T > > {
338+ pub fn join ( mut self ) -> Vec < Result < T , String > > {
341339 self . guards
342340 . drain ( ..)
343- . map ( |guard| guard. join ( ) . map_err ( |e| anyhow :: anyhow !( "{e :?}" ) ) )
341+ . map ( |guard| guard. join ( ) . map_err ( |e| format ! ( "{:?}" , e ) ) )
344342 . collect ( )
345343 }
346344}
0 commit comments