Skip to content

Fix IndexError in two error messages with a {1} placeholder - #70459

Open
kayaal34 wants to merge 1 commit into
saltstack:3008.xfrom
kayaal34:fix-format-placeholders
Open

kayaal34 wants to merge 1 commit into
saltstack:3008.xfrom
kayaal34:fix-format-placeholders

Conversation

@kayaal34

@kayaal34 kayaal34 commented Oct 21, 2026 •

Copy link
Copy Markdown

What does this PR do?

Two error messages use the format placeholder {1} with a single .format() argument, so building the message raises IndexError: Replacement index 1 out of range and the real error is lost:

  • rpmbuild_pkgbuild._get_gpg_key_resources: when gpg-preset-passphrase fails, the user gets an IndexError instead of SaltInvocationError: Failed to preset passphrase, error <rc>, ....
  • vsphere.add_host_to_dvs: when a host isn't found, the function crashes instead of returning "Host <name> not found" for that host.

Both now use {}. Targeting 3008.x (3006.x is security-only now); the same lines are also in 3007.x and master.

What issues does this PR fix or reference?

No issue; found with a static check (ruff F523/F524).

Previous Behavior

IndexError: Replacement index 1 out of range for positional args tuple

New Behavior

SaltInvocationError: Failed to preset passphrase, error 2, check logs for further details / Host esx1 not found

Merge requirements satisfied?

  • Docs
  • Changelog
  • Tests written/updated: a new test in tests/pytests/unit/modules/test_rpmbuild_pkgbuild.py mocks a failing gpg-preset-passphrase (cmd.retcode returns 2) and expects the SaltInvocationError; it fails on 3008.x with the IndexError and passes with the fix (run on Linux, Python 3.12). I didn't add a test for the vsphere line: exercising add_host_to_dvs needs pyVmomi object mocks, and the change there is the same one-character fix.

Commits signed with GPG?

No

Note: I used Claude (an AI assistant) to help find and fix this; I reviewed the change and ran the test as described.

@kayaal34
kayaal34 requested a review from a team as a code owner October 21, 2026 14:22
@dwoz
dwoz changed the base branch from 3006.x to 3008.x October 22, 2026 00:11
@dwoz

dwoz commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@kayaal34 3006.x has entered security only. Please rebase these changes on 3008.x

The passphrase error in rpmbuild_pkgbuild._get_gpg_key_resources and the
'host not found' message in vsphere.add_host_to_dvs used '{1}' with a single
format argument, so building the message raised IndexError and hid the
real error.
@kayaal34
kayaal34 force-pushed the fix-format-placeholders branch from 8a4a2ff to 73cd3ba Compare October 23, 2026 09:38
@kayaal34

Copy link
Copy Markdown
Author

Thanks, rebased onto 3008.x and retargeted the PR. On 3008.x the new test lives in the existing test_rpmbuild_pkgbuild.py (reusing _masking_pillar_get); it still fails with the IndexError without the fix and passes with it.

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.

2 participants