From 55531c1497fe64cc2d087b8f81e5654869dac1d0 Mon Sep 17 00:00:00 2001 From: Martin Kourim Date: Fri, 19 Dec 2025 17:44:45 +0100 Subject: [PATCH] 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. --- cardano_node_tests/utils/cluster_nodes.py | 2 +- cardano_node_tests/utils/helpers.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cardano_node_tests/utils/cluster_nodes.py b/cardano_node_tests/utils/cluster_nodes.py index 5ae9d2c97..ef6c972d3 100644 --- a/cardano_node_tests/utils/cluster_nodes.py +++ b/cardano_node_tests/utils/cluster_nodes.py @@ -392,7 +392,7 @@ def start_cluster(cmd: str, args: list[str]) -> clusterlib.ClusterLib: args_str = " ".join(args) args_str = f" {args_str}" if args_str else "" LOGGER.info(f"Starting cluster with `{cmd}{args_str}`.") - helpers.run_command(f"{cmd}{args_str}", workdir=get_cluster_env().work_dir) + helpers.run_command(f"{cmd}{args_str}", workdir=get_cluster_env().work_dir, merge_stderr=True) LOGGER.info("Cluster started.") return get_cluster_type().get_cluster_obj() diff --git a/cardano_node_tests/utils/helpers.py b/cardano_node_tests/utils/helpers.py index 065da90e3..01814a04c 100644 --- a/cardano_node_tests/utils/helpers.py +++ b/cardano_node_tests/utils/helpers.py @@ -81,9 +81,9 @@ def run_command( workdir: ttypes.FileType = "", ignore_fail: bool = False, shell: bool = False, + merge_stderr: bool = False, ) -> bytes: """Run command.""" - cmd: str | list if isinstance(command, str): cmd = command if shell else command.split() cmd_str = command @@ -94,14 +94,17 @@ def run_command( LOGGER.debug("Running `%s`", cmd_str) with subprocess.Popen( - cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=shell, cwd=workdir or None + cmd, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT if merge_stderr else subprocess.PIPE, + shell=shell, + cwd=workdir or None, ) as p: stdout, stderr = p.communicate() retcode = p.returncode if not ignore_fail and retcode != 0: - err_dec = stderr.decode() - err_dec = err_dec or stdout.decode() + err_dec = (stderr or stdout).decode() msg = f"An error occurred while running `{cmd_str}`: {err_dec}" raise RuntimeError(msg)