Skip to content

Commit 2c87d77

Browse files
committed
fix(cluster): merge stderr with stdout in run_command
Update the `run_command` helper to support merging stderr with stdout using the `merge_stderr` parameter. This ensures error output is captured in the same stream, improving logging and debugging. Applied in `start_cluster` to simplify cluster startup diagnostics.
1 parent 3d7da57 commit 2c87d77

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

cardano_node_tests/utils/cluster_nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def start_cluster(cmd: str, args: list[str]) -> clusterlib.ClusterLib:
392392
args_str = " ".join(args)
393393
args_str = f" {args_str}" if args_str else ""
394394
LOGGER.info(f"Starting cluster with `{cmd}{args_str}`.")
395-
helpers.run_command(f"{cmd}{args_str}", workdir=get_cluster_env().work_dir)
395+
helpers.run_command(f"{cmd}{args_str}", workdir=get_cluster_env().work_dir, merge_stderr=True)
396396
LOGGER.info("Cluster started.")
397397
return get_cluster_type().get_cluster_obj()
398398

cardano_node_tests/utils/helpers.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ def run_command(
8181
workdir: ttypes.FileType = "",
8282
ignore_fail: bool = False,
8383
shell: bool = False,
84+
merge_stderr: bool = False,
8485
) -> bytes:
8586
"""Run command."""
86-
cmd: str | list
8787
if isinstance(command, str):
8888
cmd = command if shell else command.split()
8989
cmd_str = command
@@ -94,14 +94,17 @@ def run_command(
9494
LOGGER.debug("Running `%s`", cmd_str)
9595

9696
with subprocess.Popen(
97-
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=shell, cwd=workdir or None
97+
cmd,
98+
stdout=subprocess.PIPE,
99+
stderr=subprocess.STDOUT if merge_stderr else subprocess.PIPE,
100+
shell=shell,
101+
cwd=workdir or None,
98102
) as p:
99103
stdout, stderr = p.communicate()
100104
retcode = p.returncode
101105

102106
if not ignore_fail and retcode != 0:
103-
err_dec = stderr.decode()
104-
err_dec = err_dec or stdout.decode()
107+
err_dec = (stderr or stdout).decode()
105108
msg = f"An error occurred while running `{cmd_str}`: {err_dec}"
106109
raise RuntimeError(msg)
107110

0 commit comments

Comments
 (0)