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 <jan@janware.com>
This commit is contained in:
parent
3ac649cdf1
commit
d8ed0c95d3
1 changed files with 11 additions and 3 deletions
|
|
@ -300,9 +300,17 @@ class App: # export
|
||||||
pr.enable()
|
pr.enable()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ret = await self._run(self.__args)
|
result = await self._run(self.__args)
|
||||||
if isinstance(ret, int) and ret >= 0 and ret <= 0xFF:
|
if isinstance(result, int):
|
||||||
exit_status = ret
|
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:
|
except Exception as e:
|
||||||
log_m(ERR, f'Failed: {repr(e) if self.__back_trace else str(e)}')
|
log_m(ERR, f'Failed: {repr(e) if self.__back_trace else str(e)}')
|
||||||
exit_status = 1
|
exit_status = 1
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue