Skip to content

Keep the real exit status of kiwi-ng - #3096

Open
Test-bot-cell wants to merge 1 commit into
OSInside:mainfrom
Test-bot-cell:fix-exit-status
Open

Test-bot-cell wants to merge 1 commit into
OSInside:mainfrom
Test-bot-cell:fix-exit-status

Conversation

@Test-bot-cell

Copy link
Copy Markdown

Summary

kiwi-ng --version, kiwi-ng --help and a manual page request (kiwi-ng system build help) exit with status 1, and usage errors exit with status 1 instead of 2:

$ kiwi-ng --version; echo $?
KIWI (next generation) version 11.1.5
1
$ kiwi-ng --no-such-option >/dev/null 2>&1; echo $?
1

Two causes:

  • Cli.__init__ runs the typer application in standalone mode, which always ends with SystemExit once the command line is parsed. The exception was swallowed and, when no command callback had run (--help, --version, a manual page request), sys.exit(1) was forced; usage errors (status 2) were also turned into status 1.
  • main() in kiwi/kiwi.py passed the SystemExit object to sys.exit() instead of its code, which Python reports as status 1.

Change

  • kiwi/cli.py: keep the status of the SystemExit raised by typer: the real code for a usage error, 0 for a clean exit without a command to run. The existing sys.exit(1) when no command was loaded and nothing exited is unchanged.
  • kiwi/kiwi.py: pass the SystemExit code through unchanged.
  • test/unit/cli_test.py: regression test test_exit_status_without_command (--version and --help exit 0, an unknown option exits 2).

Testing

  • pytest test/unit/cli_test.py: 27 passed (26 existing + the new test), run against the patched package installed on Ubuntu 26.04.
  • The full upstream unit test suite (2001 tests) passes with this change applied to the 11.1.5 release, built with sbuild on Ubuntu 26.04 (we carry it as a DEP-3 patch in a downstream package).
  • Manual check after the change: --version, --help, system build --help, image info --help and system build help exit 0; --no-such-option and system build without options exit 2; a successful system build is not affected (normal return path).

Found while packaging kiwi 11.1.5 for an Ubuntu derivative: scripts testing kiwi-ng --version saw status 1.

🤖 Generated with Claude Code

Cli.__init__ runs the typer application in standalone mode, which always
ends with SystemExit once the command line is parsed. The exception was
swallowed and, when no command callback had run (--help, --version, a
manual page request), sys.exit(1) was forced; usage errors (status 2)
were also turned into status 1. The status of the SystemExit is now
kept: 0 for a clean exit without a command, the real code for a usage
error.

main() also passed the SystemExit object to sys.exit() instead of its
code, which Python reports as status 1; the code is passed through
unchanged.

Found while packaging kiwi 11.1.5 for a Ubuntu derivative: scripts
testing `kiwi-ng --version` saw status 1.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant