Run a subprocess command with error handling.
(cmd: list, check: bool = True)
| 130 | |
| 131 | |
| 132 | def run_command(cmd: list, check: bool = True) -> subprocess.CompletedProcess: |
| 133 | """Run a subprocess command with error handling.""" |
| 134 | try: |
| 135 | result = subprocess.run(cmd, capture_output=True, text=True, check=check) |
| 136 | return result |
| 137 | except subprocess.CalledProcessError as e: |
| 138 | if check: |
| 139 | log_error(f"Command failed: {' '.join(cmd)}") |
| 140 | log_error(f"Error: {e.stderr.strip() if e.stderr else str(e)}") |
| 141 | raise |
| 142 | return e |
| 143 | |
| 144 | |
| 145 | def reset_postgresql(host: str = None, port: str = None, user: str = None, database: str = None): |
no test coverage detected