From 88241fc359eb1f734bd2b139b68430a94b913022 Mon Sep 17 00:00:00 2001 From: Miguel Angel Ajo Pelayo Date: Fri, 28 Nov 2025 12:17:42 +0100 Subject: [PATCH] j: return exit code properly fixes the bug of j tmt always returning 0 click in standalone_mode=False mode, as we use it in j, will not raise the click.Exception.Exit but instead return the result as an integer. this commit looks for the integer, and raisex the exception that can be caught on the external try block. --- packages/jumpstarter-cli/jumpstarter_cli/j.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/jumpstarter-cli/jumpstarter_cli/j.py b/packages/jumpstarter-cli/jumpstarter_cli/j.py index a27e24fe5..fdb7e3391 100644 --- a/packages/jumpstarter-cli/jumpstarter_cli/j.py +++ b/packages/jumpstarter-cli/jumpstarter_cli/j.py @@ -26,7 +26,9 @@ async def cli(): async with BlockingPortal() as portal: with ExitStack() as stack: async with env_async(portal, stack) as client: - await to_thread.run_sync(lambda: client.cli()(standalone_mode=False)) + result = await to_thread.run_sync(lambda: client.cli()(standalone_mode=False)) + if isinstance(result, int) and result != 0: + raise BaseExceptionGroup("CLI exit", [click.exceptions.Exit(result)]) except BaseExceptionGroup as eg: # Handle exceptions wrapped in ExceptionGroup (e.g., from task groups) if exc := find_exception_in_group(eg, EnvironmentVariableNotSetError): @@ -40,6 +42,9 @@ async def cli(): await cli() finally: tg.cancel_scope.cancel() + except* click.exceptions.Exit as excgroup: + for exc in leaf_exceptions(excgroup): + sys.exit(exc.exit_code) except* click.ClickException as excgroup: for exc in leaf_exceptions(excgroup): cast(click.ClickException, exc).show()