[elbe-devel] [PATCH 01/11] elbepack: main: propagate exceptions from run_elbe_subcommand()

Thomas Weißschuh thomas.weissschuh at linutronix.de
Thu Aug 8 11:38:12 CEST 2024


The exceptions encountered from run_elbe_subcommand() should be
preserved and not replaced by SystemExit in sys.exit().

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/directories.py | 2 +-
 elbepack/main.py        | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/elbepack/directories.py b/elbepack/directories.py
index e58a7e50841a..0a8105442ab5 100644
--- a/elbepack/directories.py
+++ b/elbepack/directories.py
@@ -15,5 +15,5 @@ def run_elbe(args, **kwargs):
 
 def run_elbe_subcommand(args):
     return elbepack.main.main([
-        'elbe', *[os.fspath(arg) for arg in args],
+        'elbe', '--propagate-exception', *[os.fspath(arg) for arg in args],
     ])
diff --git a/elbepack/main.py b/elbepack/main.py
index cc169296794b..4bfd248b02d0 100644
--- a/elbepack/main.py
+++ b/elbepack/main.py
@@ -20,6 +20,8 @@ def main(argv=sys.argv):
     parser = argparse.ArgumentParser(prog='elbe')
     parser.add_argument('--version', action='version', version=f'%(prog)s v{elbe_version}')
     parser.add_argument('--stacktrace-on-error', action='store_true', dest='stacktrace_on_error')
+    parser.add_argument('--propagate-exception', action='store_true', dest='propagate_exception',
+                        help=argparse.SUPPRESS)
 
     subparsers = parser.add_subparsers(required=True, dest='cmd')
 
@@ -33,6 +35,8 @@ def main(argv=sys.argv):
     try:
         cmdmod.run_command(cmd_argv)
     except Exception as e:
+        if args.propagate_exception:
+            raise e
         sys.exit(format_exception(e, output=sys.stderr,
                                   base_module=elbepack,
                                   verbose=args.stacktrace_on_error))

-- 
2.46.0



More information about the elbe-devel mailing list