From 572a2d542f75aefe40a20d0cfdefc4351eb0488a Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Fri, 26 Jun 2026 22:25:46 -0400 Subject: [PATCH] process: add checked subprocess helper --- tartarus/process.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tartarus/process.py diff --git a/tartarus/process.py b/tartarus/process.py new file mode 100644 index 0000000..e5732d5 --- /dev/null +++ b/tartarus/process.py @@ -0,0 +1,23 @@ +"""Checked subprocess helpers shared across the harness.""" + +import subprocess + + +class ProcessError(Exception): + """Raised when a checked subprocess command cannot be run or exits non-zero.""" + + +def run_checked(command: list[str]) -> str: + """Run a command with captured text output, raising ProcessError on failure.""" + if not command: + raise ProcessError("command is empty") + + try: + completed = subprocess.run(command, capture_output=True, text=True, check=True) + except FileNotFoundError as missing: + raise ProcessError(f"`{command[0]}` not found") from missing + except subprocess.CalledProcessError as failed: + raise ProcessError( + f"`{' '.join(command)}` failed: {failed.stderr.strip()}" + ) from failed + return completed.stdout -- 2.51.2