diff mbox series

[v3,13/14] bitbake-setup: catch unexpected exceptions and show a clean error message

Message ID 20260329183332.1996183-14-adrian.freihofer@siemens.com
State New
Headers show
Series bitbake-setup: improvements, VSCode workspace generation | expand

Commit Message

AdrianF March 29, 2026, 6:33 p.m. UTC
From: Adrian Freihofer <adrian.freihofer@siemens.com>

Without a top-level exception handler, any unexpected Python exception
reaches the user as a raw traceback, which is confusing and exposes
implementation details.

Add a try/except block around the main dispatch in main() that:
- catches all unexpected exceptions and logs them as a single ERROR
  line, consistent with how other errors are already presented
- re-raises when --debug is active, so the full traceback is still
  available for diagnosis
- explicitly re-raises SystemExit and KeyboardInterrupt so sys.exit()
  calls and Ctrl-C continue to work normally

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 bin/bitbake-setup | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/bin/bitbake-setup b/bin/bitbake-setup
index 596722e48..ddb6d2af1 100755
--- a/bin/bitbake-setup
+++ b/bin/bitbake-setup
@@ -1361,13 +1361,21 @@  def main():
 
         logger.info('Bitbake-setup is using {} as top directory.'.format(top_dir))
 
-        if args.func == init_config:
-            init_config(top_dir, all_settings, args)
-        else:
-            d = init_bb_cache(top_dir, all_settings, args)
-            args.func(top_dir, all_settings, args, d)
+        try:
+            if args.func == init_config:
+                init_config(top_dir, all_settings, args)
+            else:
+                d = init_bb_cache(top_dir, all_settings, args)
+                args.func(top_dir, all_settings, args, d)
 
-        save_bb_cache()
+            save_bb_cache()
+        except (SystemExit, KeyboardInterrupt):
+            raise
+        except Exception as e:
+            if args.debug:
+                raise
+            logger.error(str(e))
+            sys.exit(1)
     else:
         parser.print_help()