actions_utils: Fix issue with collecting stdout/stderr

- When an exception is raised in subprocess.run(), for that call the stdout and
stderr are not being collected. Any previous successful calls are being
collected.

- This also fixes issues with adding an existing backup repository back after
removal. Capturing stderr is essential for raising the proper exceptions and
working correctly.

Tests:

- Remove an existing backup repository and add it back again. It fails with the
patches and succeeds with the patches.

- Remove an existing encrypted backup repository and add it back again with the
wrong password. A proper error message is shown 'Incorrect encryption
passphrase'.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
Sunil Mohan Adapa 2025-09-25 22:22:04 -07:00 committed by Veiko Aasa
parent f559870d3e
commit 355812c9f2
No known key found for this signature in database
GPG Key ID: 478539CAE680674E

View File

@ -836,11 +836,20 @@ def run(command, **kwargs):
if collect_stderr:
kwargs['stderr'] = subprocess.PIPE
process = subprocess.run(command, **kwargs)
if collect_stdout and hasattr(actions.thread_storage, 'stdout'):
actions.thread_storage.stdout += process.stdout
try:
process = subprocess.run(command, **kwargs)
if collect_stdout and hasattr(actions.thread_storage, 'stdout'):
actions.thread_storage.stdout += process.stdout
if collect_stderr and hasattr(actions.thread_storage, 'stderr'):
actions.thread_storage.stderr += process.stderr
if collect_stderr and hasattr(actions.thread_storage, 'stderr'):
actions.thread_storage.stderr += process.stderr
except subprocess.CalledProcessError as exception:
if exception.stdout and hasattr(actions.thread_storage, 'stdout'):
actions.thread_storage.stdout += exception.stdout
if exception.stderr and hasattr(actions.thread_storage, 'stderr'):
actions.thread_storage.stderr += exception.stderr
raise exception
return process