Skip to content

Exit non-zero from batch mode when no minions match#69749

Open
ggiesen wants to merge 1 commit into
saltstack:3006.xfrom
ggiesen:fix-57357-batch-exit-code
Open

Exit non-zero from batch mode when no minions match#69749
ggiesen wants to merge 1 commit into
saltstack:3006.xfrom
ggiesen:fix-57357-batch-exit-code

Conversation

@ggiesen

@ggiesen ggiesen commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Makes the salt CLI exit 2 ("No return received") in batch mode when the target matches no minions, matching the non-batch behavior instead of silently exiting 0.

What issues does this PR fix or reference?

Fixes #57357

Previous Behavior

In batch mode the CLI's exit code was derived by iterating batch.run(). When the target matches no minions, Batch.run() returns early on an empty minion list and yields nothing, so the loop never runs, retcode stays 0, and the CLI exits 0. The non-batch path instead reaches the "No return received" guard in _output_ret and exits 2, so the two modes disagree on a no-match run.

New Behavior

After the batch loop, if no minions matched (batch.minions is empty), the CLI prints "No return received" and exits 2, matching non-batch. The --static batch branch already routes through _output_ret and was unaffected.

Note on the exit code: 2 was chosen to mirror the non-batch "No return received" path exactly (the reporter's stated expectation). If maintainers prefer a different code here I'm happy to adjust.

Merge requirements satisfied?

  • Docs - not applicable
  • Changelog - changelog/57357.fixed.md
  • Tests written/updated - tests/pytests/unit/cli/test_salt.py: no-match exits 2 (pins the bug), matched minions use the highest job retcode, matched-success exits 0

Commits signed with GPG?

No

In batch mode the salt CLI computed its exit code by iterating batch.run(),
which yields nothing when the target matches no minions (Batch.run returns
early on an empty minion list). retcode stayed 0 and the CLI exited 0, while
the non-batch path exits 2 ("No return received") for the same case
(saltstack#57357). Mirror the non-batch behavior: when no minions matched, print
"No return received" and exit 2.

Fixes saltstack#57357
@ggiesen ggiesen requested a review from a team as a code owner July 10, 2026 07:45
@charzl charzl self-assigned this Jul 10, 2026
@dwoz dwoz added the test:full Run the full test suite label Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants