From 20045ad6391470532a9e233ff48f5c291cb6dc78 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Wed, 4 Jan 2023 15:54:14 -0500 Subject: [PATCH] feat(core): add ability to take geth stderr * makes the geth logs accessible by using take() on the GethInstance stderr --- ethers-core/src/utils/geth.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ethers-core/src/utils/geth.rs b/ethers-core/src/utils/geth.rs index 8c13d1755..ce91d4920 100644 --- a/ethers-core/src/utils/geth.rs +++ b/ethers-core/src/utils/geth.rs @@ -5,7 +5,7 @@ use std::{ fs::{create_dir, File}, io::{BufRead, BufReader}, path::PathBuf, - process::{Child, Command, Stdio}, + process::{Child, ChildStderr, Command, Stdio}, time::{Duration, Instant}, }; @@ -76,7 +76,17 @@ impl GethInstance { &self.data_dir } + /// Takes the stderr contained in the child process. + /// + /// This leaves a `None` in its place, so calling methods that require a stderr to be present + /// will fail if called after this. + pub fn stderr(&mut self) -> Result { + self.pid.stderr.take().ok_or(GethInstanceError::NoStderr) + } + /// Blocks until geth adds the specified peer, using 20s as the timeout. + /// + /// Requires the stderr to be present in the `GethInstance`. pub fn wait_to_add_peer(&mut self, id: H256) -> Result<(), GethInstanceError> { let mut stderr = self.pid.stderr.as_mut().ok_or(GethInstanceError::NoStderr)?; let mut err_reader = BufReader::new(&mut stderr);