Skip to content

Commit 8acc8e7

Browse files
committed
returning an error if the subprocess failed early
closes #50
1 parent 493c0f4 commit 8acc8e7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod versions;
1515

1616
use crate::bitcoincore_rpc::jsonrpc::serde_json::Value;
1717
use bitcoincore_rpc::{Auth, Client, RpcApi};
18-
use log::debug;
18+
use log::{debug, error};
1919
use std::ffi::OsStr;
2020
use std::net::{Ipv4Addr, SocketAddrV4, TcpListener};
2121
use std::path::PathBuf;
@@ -81,6 +81,8 @@ pub enum Error {
8181
NeitherFeatureNorEnvVar,
8282
/// Returned when calling methods requiring either a feature or anv var, but both are present
8383
BothFeatureAndEnvVar,
84+
/// Wrapper of early exit status
85+
EarlyExit(ExitStatus),
8486
}
8587

8688
impl fmt::Debug for Error {
@@ -92,6 +94,7 @@ impl fmt::Debug for Error {
9294
Error::NoEnvVar => write!(f, "Called a method requiring env var `BITCOIND_EXE` to be set, but it's not"),
9395
Error::NeitherFeatureNorEnvVar => write!(f, "Called a method requiring env var `BITCOIND_EXE` or a feature to be set, but neither are set"),
9496
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),
9598
}
9699
}
97100
}
@@ -221,7 +224,7 @@ impl BitcoinD {
221224
default_args,
222225
p2p_args
223226
);
224-
let process = Command::new(exe)
227+
let mut process = Command::new(exe)
225228
.args(&default_args)
226229
.args(&p2p_args)
227230
.args(&conf.args)
@@ -231,6 +234,10 @@ impl BitcoinD {
231234
let node_url_default = format!("{}/wallet/default", rpc_url);
232235
// wait bitcoind is ready, use default wallet
233236
let client = loop {
237+
if let Some(status) = process.try_wait()? {
238+
error!("early exit with: {:?}", status);
239+
return Err(Error::EarlyExit(status));
240+
}
234241
thread::sleep(Duration::from_millis(500));
235242
assert!(process.stderr.is_none());
236243
let client_result = Client::new(&rpc_url, Auth::CookieFile(cookie_file.clone()));

0 commit comments

Comments
 (0)