Repository navigation
Fix Fleet Dashboard 500 and other __() calls given too few values - #60
Merged
Merged
Conversation
Cacti's __() formats at once when given more than the text, and the text domain counts as a sprintf value, so sprintf(__('%s of %s rated', 'apcupsd'), ...) threw an ArgumentCountError (the dashboard 500) and single-placeholder strings printed 'apcupsd' instead of the value. The same pattern in the NUT connect message crashed the poller whenever upsd was unreachable. Pass the values to __() before the text domain at all 15 sites.
Make the test __() stub mirror Cacti, and add a source scan that fails if the mistake returns.
Fixes #59
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
There was a problem hiding this comment.
🟢 Approval recommended
The focused corrections match Cacti’s formatting contract, with regression coverage and no unresolved findings.
No open issues 🎉
What changed in this PR
Fixes translation formatting across the apcupsd plugin, addressing the Fleet Dashboard error in #59 and a possible cause of the polling failure in #57.
Changes:
- Corrects 15 translation calls to pass values before the text domain.
- Updates translation stubs and adds regression tests.
- Documents the fixes in the changelog.
| File | Description |
|---|---|
| upses.php | Fixes Graph Automation messages. |
| tests/Unit/I18nPlaceholderTest.php | Adds placeholder and NUT message regression tests. |
| tests/bootstrap-unit.php | Makes translation stubs format supplied values. |
| poller_apcupsd.php | Fixes the apcaccess timeout message. |
| includes/nut.php | Fixes NUT error and timeout messages. |
| includes/dashboard.php | Fixes gauge summaries and estimated-load formatting. |
| CHANGELOG.md | Documents crashes and incorrect messages addressed. |
Review effort: Balanced
bmfmancini
approved these changes
Oct 17, 2026
3 of 4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
Fixes the Fleet Dashboard returning a 500 error, and the same mistake in 14 other translated strings.
Cacti's
__()formats a string as soon as it is given more than the text: the text domain counts as just anothersprintfvalue. The plugin called it assprintf(__('%s of %s rated', 'apcupsd'), $load, $capacity), so__()itself ransprintf('%s of %s rated', 'apcupsd'), which has one value for two placeholders and throwsArgumentCountError("3 arguments are required, 2 given", the exact error in #59).Every string with a placeholder now passes its values to
__()before the text domain, with nosprintf()wrapper:15 call sites in
includes/dashboard.php(8),includes/nut.php(4),upses.php(2) andpoller_apcupsd.php(1). The string literals are unchanged, so the translation template does not change.Besides the dashboard crash this fixes:
apcupsd_nut_query()builds its "Unable to connect to the NUT server %s: %s" message the same way, so a refused or unreachableupsdthrew the sameArgumentCountErrorinside the background poller. With its output discarded, the poller died silently: no status for that UPS, the remaining UPSes not polled, and noAPCUPSD STATSline. That matches the symptoms in NUT UPSes polling is not working #57.Related Issue
Fixes #59
Related to #57 (the poller crash above is the likely cause of its "Unknown" status and empty log, but I have not been able to confirm that on a real Cacti install).
Motivation and Context
The test bootstrap's
__()stub just returned the text, sosprintf(__(...), ...)always worked in tests and nothing could catch this. The stub now mirrors Cacti's__(): it formats at once, the trailing domain is one more value, and too few values throw. A new test scans the plugin's source with PHP's tokenizer and fails if any__()or__esc()call has a placeholder with only the text domain after it, so the mistake cannot come back unnoticed.How Has This Been Tested?
php -lis clean on every changed PHP file.NutClientTest.tests/Unit/I18nPlaceholderTest.phpcovers the source scan (and that the scanner flags the broken form), the Cacti-faithful formatting, and the NUT error messages. The same scan found exactly these 15 sites on the unmodifieddevelopcode.__()source and the stack trace in The NUT UPS seems to be working again, but the Fleet Dashboard tab shown a 500 error #59.Types of changes
Checklist: