Interview Prep/Python for DevOps/Runtime, file, subprocess & encoding errors

`subprocess.CalledProcessError: Command '['terraform', 'plan']' returned non-zero exit status 1.` with no further detail.

BeginnerTroubleshootingRuntime, file, subprocess & encoding errors
Answer

Likely causes → The command failed, but stderr was not captured or not logged.

Diagnose →

try:
    subprocess.run(cmd, check=True, capture_output=True, text=True)
except subprocess.CalledProcessError as e:
    print(e.stderr)

Fix → Capture output and log e.stdout and e.stderr on failure (or let output stream to the console if not capturing).

Prevent → A shared run() helper that always logs the command, exit code and stderr on failure.

All Python for DevOps questions Roadmap: Python for automation

More on Runtime, file, subprocess & encoding errors