fix: Find substrate port on different log lines (#536)

* Find substrate port on different log lines

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Simplify node_proc line logic

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2022-05-12 17:29:07 +03:00
committed by GitHub
parent 31f8c37164
commit ae59c8a663
+11 -9
View File
@@ -168,22 +168,24 @@ fn find_substrate_port_from_output(r: impl Read + Send + 'static) -> u16 {
BufReader::new(r) BufReader::new(r)
.lines() .lines()
.find_map(|line| { .find_map(|line| {
let line = line let line =
.expect("failed to obtain next line from stdout for port discovery"); line.expect("failed to obtain next line from stdout for port discovery");
// does the line contain our port (we expect this specific output from substrate). // does the line contain our port (we expect this specific output from substrate).
let line_end = match line.rsplit_once("Listening for new connections on 127.0.0.1:") { let line_end = line
None => return None, .rsplit_once("Listening for new connections on 127.0.0.1:")
Some((_, after)) => after .or_else(|| {
}; line.rsplit_once("Running JSON-RPC WS server: addr=127.0.0.1:")
})
.map(|(_, port_str)| port_str)?;
// trim non-numeric chars from the end of the port part of the line. // trim non-numeric chars from the end of the port part of the line.
let port_str = line_end.trim_end_matches(|b| !('0'..='9').contains(&b)); let port_str = line_end.trim_end_matches(|b| !('0'..='9').contains(&b));
// expect to have a number here (the chars after '127.0.0.1:') and parse them into a u16. // expect to have a number here (the chars after '127.0.0.1:') and parse them into a u16.
let port_num = port_str let port_num = port_str.parse().unwrap_or_else(|_| {
.parse() panic!("valid port expected for log line, got '{port_str}'")
.unwrap_or_else(|_| panic!("valid port expected on 'Listening for new connections' line, got '{port_str}'")); });
Some(port_num) Some(port_num)
}) })