Repository navigation
Fix plugin-disabling TypeError in mikrotik_graphs_url_by_template_hashs() when hash globals are null - #118
Merged
Conversation
mikrotik_graphs_url_by_template_hashs() declared its \ parameter as a strict array. The wireless APs view passes the \ global (and the wireless registrations view passes \), neither of which is ever populated in mikrotik_config_arrays(), so they are null. Under strict typing this throws an uncaught TypeError that Cacti traps and then disables the plugin. Make the parameter nullable so an unpopulated hash list renders the existing graceful 'Graphs Skipped by Rule, or Not Created' placeholder (cacti_sizeof(null) is 0) instead of crashing.
TheWitness
requested review from
bmfmancini and
xmacan
and
a balanced review from Copilot
October 8, 2026 22:57
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The fallback masks incorrect registration-hash wiring, lacks a null regression test, and needs a changelog entry.
3 open findings
What changed in this PR
Prevents null hash globals from triggering a plugin-disabling TypeError.
Changes:
- Allows nullable graph-template hash lists.
- Documents placeholder behavior for null lists.
| File | Description |
|---|---|
setup.php |
Adds nullable hash-list handling and PHPDoc. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Correct the \ typo in mikrotik_config_arrays() and align mikrotik_wireless_regs() to the \ global so Wireless Registrations graph links resolve instead of being masked by the null fallback. - Make the empty \ list explicit (no AP station graph templates currently ship), so the nullable fallback is reserved for genuinely empty views. - Add a null-input regression test for mikrotik_graphs_url_by_template_hashs(). - Record the fix under the develop section of CHANGELOG.md.
bmfmancini
previously approved these changes
Oct 8, 2026
The patch-coverage gate flagged the changed global declaration and the new empty \ assignment in mikrotik_config_arrays() as uncovered. Add a SetupWiringTest case that invokes the function and asserts the published wireless registration and AP station hash globals.
bmfmancini
approved these changes
Oct 8, 2026
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
mikrotik_graphs_url_by_template_hashs()insetup.phpdeclared its firstparameter with a strict
arraytype hint:The Wireless APs view (
mikrotik_wireless_aps()) calls it with the$wireless_station_hashesglobal, and the Wireless Registrations view(
mikrotik_wireless_regs()) calls it with the$wreg_hashesglobal. Neitherglobal is ever populated in
mikrotik_config_arrays(), so both arenull.Under strict typing, passing
nullthrows an uncaughtTypeError, which Cactitraps in its shutdown handler and then disables the plugin:
This change makes the
$hashesparameter nullable (?array). The functionalready renders a graceful "Graphs Skipped by Rule, or Not Created" placeholder
whenever the hash list is empty (
cacti_sizeof(null)returns0), so anunpopulated hash global now produces that placeholder instead of a fatal error.
Related Issue
Fixes the runtime
TypeErrorreported frommikrotik.phpline 1464 that causesCacti to disable the
mikrotikplugin.Motivation and Context
A fatal
TypeErrorreaching Cacti's shutdown handler causes the entire pluginto be auto-disabled, taking down all MikroTik collection and views. Guarding the
single boundary function that receives these (currently unpopulated) hash list
globals resolves the crash for both the Wireless APs and Wireless Registrations
views without changing any existing, working behavior.
How Has This Been Tested?
php -l setup.php— no syntax errors.mikrotik_graphs_url_by_template_hashs()(interfaces/queues/trees/wireless APs/users/wireless regs); the four with
populated hash globals are unaffected, and the two with
nullglobals nowrender the placeholder link instead of throwing.
Types of changes
Checklist: