diff mbox series

[auh,07/11] upgrade-helper.py: fix exception handling for commit_changes

Message ID 20260311063557.229656-7-Qi.Chen@windriver.com
State New
Headers show
Series [auh,01/11] upgrade-helper.py: remove unused self.poky_git settings | expand

Commit Message

ChenQi March 11, 2026, 6:35 a.m. UTC
From: Chen Qi <Qi.Chen@windriver.com>

The previous exception handling is basically self-contradictory.
It has g['error'] = e below, so it thinks e is of type Error.
But it does not make use of Error's message, stdout and stderr.
And the e could well not be of type Error.

Fix the logic by checking the type of e and handles it differently.

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
 upgrade-helper.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/upgrade-helper.py b/upgrade-helper.py
index 27e1f48..428d66f 100755
--- a/upgrade-helper.py
+++ b/upgrade-helper.py
@@ -523,8 +523,11 @@  class Updater(object):
             try:
                 self.commit_changes(g)
             except Exception as e:
-                import traceback
-                E(" Couldn't commit changes to %s:\n%s" % (pkggroup_name, traceback.format_exc()))
+                if not isinstance(e, Error):
+                    import traceback
+                    msg = "Failed(unknown error)\n" + traceback.format_exc()
+                    e = Error(message=msg)
+                E(" Couldn't commit changes to %s:\nmessage: %s\nstdout: %s\nstderr: %s" % (pkggroup_name, e.message, e.stdout, e.stderr))
                 # Ensure commit failures are recorded as group errors
                 g['error'] = e
                 if g in succeeded_pkggroups_ctx: