improve debug logging for command failures

This commit is contained in:
Whispering Wind
2025-01-26 00:39:45 +03:30
committed by GitHub
parent 0288429bc8
commit 34a2e796db

View File

@ -78,12 +78,15 @@ def run_cmd(command: list[str]) -> str | None:
if (DEBUG) and not (Command.GET_USER.value in command or Command.LIST_USERS.value in command):
print(' '.join(command))
try:
result = subprocess.check_output(command, shell=False)
result = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=False)
if result:
result = result.decode().strip()
return result
except subprocess.CalledProcessError as e:
raise CommandExecutionError(f"Command execution failed: {e}")
if DEBUG:
raise CommandExecutionError(f"Command execution failed: {e}\nOutput: {e.output.decode()}")
else:
return None
return None