Skip to content

Fix plugin-disabling TypeError in mikrotik_graphs_url_by_template_hashs() when hash globals are null - #118

Merged
TheWitness merged 3 commits into
developfrom
fix/graphs-url-null-hashes-typeerror
Oct 8, 2026
Merged

TheWitness merged 3 commits into
developfrom
fix/graphs-url-null-hashes-typeerror

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Description

mikrotik_graphs_url_by_template_hashs() in setup.php declared its first
parameter with a strict array type hint:

function mikrotik_graphs_url_by_template_hashs(array $hashes, int $host_id = 0, string $search = ''): string

The Wireless APs view (mikrotik_wireless_aps()) calls it with the
$wireless_station_hashes global, and the Wireless Registrations view
(mikrotik_wireless_regs()) calls it with the $wreg_hashes global. Neither
global is ever populated in mikrotik_config_arrays(), so both are null.
Under strict typing, passing null throws an uncaught TypeError, which Cacti
traps in its shutdown handler and then disables the plugin:

Uncaught TypeError: mikrotik_graphs_url_by_template_hashs(): Argument #1 ($hashes)
must be of type array, null given, called in .../mikrotik/mikrotik.php on line 1464
and defined in .../mikrotik/setup.php:1121

This change makes the $hashes parameter nullable (?array). The function
already renders a graceful "Graphs Skipped by Rule, or Not Created" placeholder
whenever the hash list is empty (cacti_sizeof(null) returns 0), so an
unpopulated hash global now produces that placeholder instead of a fatal error.

Related Issue

Fixes the runtime TypeError reported from mikrotik.php line 1464 that causes
Cacti to disable the mikrotik plugin.

Motivation and Context

A fatal TypeError reaching Cacti's shutdown handler causes the entire plugin
to 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.
  • Confirmed all six call sites of 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 null globals now
    render the placeholder link instead of throwing.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation repository accordingly.

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
TheWitness requested review from bmfmancini and xmacan and a balanced review from Copilot October 8, 2026 22:57

Copilot AI 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.

🟡 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.

Comment thread setup.php Resolved
Comment thread setup.php Resolved
Comment thread setup.php Resolved
- 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
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.
@TheWitness
TheWitness merged commit ad08b69 into develop Oct 8, 2026
3 checks passed
@TheWitness
TheWitness deleted the fix/graphs-url-null-hashes-typeerror branch October 20, 2026 17:34
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