Skip to content

fix(application): preserve non-success dispatcher return codes - #1068

Merged
mr-cal merged 3 commits into
canonical:mainfrom
gcomneno:contrib/snapcraft-6119-exit-code
May 27, 2026
Merged

fix(application): preserve non-success dispatcher return codes#1068
mr-cal merged 3 commits into
canonical:mainfrom
gcomneno:contrib/snapcraft-6119-exit-code

Conversation

@gcomneno

@gcomneno gcomneno commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Preserve explicit return codes from dispatcher.run() in Application._run_inner() while keeping the existing success fallback for commands that do not return a value.

Previously, _run_inner() used:

  • dispatcher.run() or os.EX_OK
  • dispatcher.run() or 0

This meant falsy explicit return codes could be normalized incorrectly. In particular, this change avoids relying on truthiness and only falls back when dispatcher.run() returns None.

With this change:

  • None falls back to os.EX_OK
  • 0 is preserved as 0
  • non-zero return codes are preserved

Testing

uv run ruff check craft_application/application.py tests/unit/test_application.py tests/integration/commands/test_init.py
uv run ruff format --check craft_application/application.py tests/unit/test_application.py tests/integration/commands/test_init.py
uv run pytest -q tests/unit/test_application.py tests/integration/commands/test_init.py -rs

@gcomneno

Copy link
Copy Markdown
Contributor Author

Hi! Just gently checking whether there’s anything I should adjust here.

This PR is intended to preserve non-success dispatcher return codes while keeping the existing success-path behaviour unchanged.

Happy to rework it if there’s a preferred direction, or to close it if this should not move forward.

@mr-cal mr-cal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! Can you resolve the conflicts so we can land this?

This class got simplified, so your changes should be even simpler (one instance of this logic instead of two).

…119-exit-code

# Conflicts:
#	craft_application/application.py

@lengau lengau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@lengau
lengau requested a review from mr-cal May 27, 2026 09:19
@mr-cal
mr-cal merged commit 58e0440 into canonical:main May 27, 2026
19 checks passed
@gcomneno
gcomneno deleted the contrib/snapcraft-6119-exit-code branch May 28, 2026 09:09
@mr-cal

mr-cal commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

FYI to anyone who looks at this PR in the future - this PR makes a semantic correction of doing an explicit comparison against None, rather than relying on falsiness.

But since the only falsy exit code is 0 (EX_OK) is a successful code, this doesn't make behavioral changes nor resolve canonical/snapcraft#6119.

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.

3 participants