@@ -15,7 +15,7 @@ mod versions;
15
15
16
16
use crate :: bitcoincore_rpc:: jsonrpc:: serde_json:: Value ;
17
17
use bitcoincore_rpc:: { Auth , Client , RpcApi } ;
18
- use log:: debug;
18
+ use log:: { debug, error } ;
19
19
use std:: ffi:: OsStr ;
20
20
use std:: net:: { Ipv4Addr , SocketAddrV4 , TcpListener } ;
21
21
use std:: path:: PathBuf ;
@@ -81,6 +81,8 @@ pub enum Error {
81
81
NeitherFeatureNorEnvVar ,
82
82
/// Returned when calling methods requiring either a feature or anv var, but both are present
83
83
BothFeatureAndEnvVar ,
84
+ /// Wrapper of early exit status
85
+ EarlyExit ( ExitStatus ) ,
84
86
}
85
87
86
88
impl fmt:: Debug for Error {
@@ -92,6 +94,7 @@ impl fmt::Debug for Error {
92
94
Error :: NoEnvVar => write ! ( f, "Called a method requiring env var `BITCOIND_EXE` to be set, but it's not" ) ,
93
95
Error :: NeitherFeatureNorEnvVar => write ! ( f, "Called a method requiring env var `BITCOIND_EXE` or a feature to be set, but neither are set" ) ,
94
96
Error :: BothFeatureAndEnvVar => write ! ( f, "Called a method requiring env var `BITCOIND_EXE` or a feature to be set, but both are set" ) ,
97
+ Error :: EarlyExit ( e) => write ! ( f, "The bitcoind process terminated early with exit code {}" , e) ,
95
98
}
96
99
}
97
100
}
@@ -221,7 +224,7 @@ impl BitcoinD {
221
224
default_args,
222
225
p2p_args
223
226
) ;
224
- let process = Command :: new ( exe)
227
+ let mut process = Command :: new ( exe)
225
228
. args ( & default_args)
226
229
. args ( & p2p_args)
227
230
. args ( & conf. args )
@@ -231,6 +234,10 @@ impl BitcoinD {
231
234
let node_url_default = format ! ( "{}/wallet/default" , rpc_url) ;
232
235
// wait bitcoind is ready, use default wallet
233
236
let client = loop {
237
+ if let Some ( status) = process. try_wait ( ) ? {
238
+ error ! ( "early exit with: {:?}" , status) ;
239
+ return Err ( Error :: EarlyExit ( status) ) ;
240
+ }
234
241
thread:: sleep ( Duration :: from_millis ( 500 ) ) ;
235
242
assert ! ( process. stderr. is_none( ) ) ;
236
243
let client_result = Client :: new ( & rpc_url, Auth :: CookieFile ( cookie_file. clone ( ) ) ) ;
0 commit comments