From 355812c9f21b387fe9cb18be0d13534ded897e3a Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Thu, 25 Sep 2025 22:22:04 -0700 Subject: [PATCH] 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 Reviewed-by: Veiko Aasa --- plinth/action_utils.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/plinth/action_utils.py b/plinth/action_utils.py index 5e5e87f68..0b7800cef 100644 --- a/plinth/action_utils.py +++ b/plinth/action_utils.py @@ -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