diff --git a/pmb/helpers/run_core.py b/pmb/helpers/run_core.py index 789ec7f9..ccf6383f 100644 --- a/pmb/helpers/run_core.py +++ b/pmb/helpers/run_core.py @@ -216,7 +216,8 @@ def check_return_code(args, code, log_message): logging.debug("^" * 70) logging.info("NOTE: The failed command's output is above the ^^^ line" " in the log file: " + args.log) - raise RuntimeError("Command failed: " + log_message) + raise RuntimeError(f"Command failed (exit code {str(code)}): " + + log_message) def sudo_timer_iterate(): diff --git a/test/test_run_core.py b/test/test_run_core.py index fd269537..c2d5b884 100644 --- a/test/test_run_core.py +++ b/test/test_run_core.py @@ -1,6 +1,7 @@ # Copyright 2022 Oliver Smith # SPDX-License-Identifier: GPL-3.0-or-later """ Test pmb.helpers.run_core """ +import re import sys import subprocess import pytest @@ -146,13 +147,13 @@ def test_core(args): # Check the return code with pytest.raises(RuntimeError) as e: func(args, msg, ["false"], output="log") - assert str(e.value).startswith("Command failed:") + assert re.search(r"^Command failed \(exit code -?\d*\): ", str(e.value)) # Kill with timeout args.timeout = 0.2 with pytest.raises(RuntimeError) as e: func(args, msg, ["sleep", "1"], output="log") - assert str(e.value).startswith("Command failed:") + assert re.search(r"^Command failed \(exit code -?\d*\): ", str(e.value)) @pytest.mark.skip_ci