From d8ed0c95d3db65efe2ed304ae45f90210b3ac515 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Sat, 15 Aug 2026 00:00:13 +0200 Subject: [PATCH] lib.App: Warn on invalid exit status __run() only accepts a return value from _run() as the process exit status if it is an int between 0 and 255, and silently drops any other value. A command that returns, for instance, 300 therefore exits with status 0, which presents a failure as a success to the caller without any trace of the mistake. Log an error when the returned exit status is out of range so that the programming error is visible, while still exiting with 0 instead of passing an invalid status to the shell. Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2 Signed-off-by: Jan Lindemann --- src/python/jw/pkg/lib/App.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/python/jw/pkg/lib/App.py b/src/python/jw/pkg/lib/App.py index 123aad2f..01e3bb3c 100644 --- a/src/python/jw/pkg/lib/App.py +++ b/src/python/jw/pkg/lib/App.py @@ -300,9 +300,17 @@ class App: # export pr.enable() try: - ret = await self._run(self.__args) - if isinstance(ret, int) and ret >= 0 and ret <= 0xFF: - exit_status = ret + result = await self._run(self.__args) + if isinstance(result, int): + if 0 <= result <= 0xFF: + exit_status = result + else: + log( + WARNING, + f'Command returned invalid exit status {result}, ' + 'using 1 instead', + ) + exit_status = 1 except Exception as e: log_m(ERR, f'Failed: {repr(e) if self.__back_trace else str(e)}') exit_status = 1