Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add ability to take geth stderr #2010

Merged
merged 1 commit into from Jan 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion ethers-core/src/utils/geth.rs
Expand Up @@ -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},
};

Expand Down Expand Up @@ -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<ChildStderr, GethInstanceError> {
self.pid.stderr.take().ok_or(GethInstanceError::NoStderr)
Comment on lines +83 to +84
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could also do an Option but since we already have NoStdErr, let's use this result

}

/// 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);
Expand Down