Skip to content

Return empty array instead of null when plugin update checking fails#2364

Open
Boy132 wants to merge 1 commit into
mainfrom
boy132/fix-too-many-requests
Open

Return empty array instead of null when plugin update checking fails#2364
Boy132 wants to merge 1 commit into
mainfrom
boy132/fix-too-many-requests

Conversation

@Boy132
Copy link
Copy Markdown
Member

@Boy132 Boy132 commented May 29, 2026

With null the update check is repeated each request which can slow down the panel.

@Boy132 Boy132 self-assigned this May 29, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 29, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

The PR changes Plugin::getUpdateData() to return an empty array instead of null when an exception occurs during update JSON fetch or parsing. Downstream methods isUpdateAvailable() and getDownloadUrlForUpdate() now handle the failed fetch as an empty array rather than a null value.

Changes

Plugin update data exception handling

Layer / File(s) Summary
Update data exception return value
app/Models/Plugin.php
In getUpdateData(), the exception-handling path now returns [] rather than null.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: returning an empty array instead of null when plugin update checking fails.
Description check ✅ Passed The description explains the rationale for the change by clarifying that null causes repeated update checks which can slow down the panel.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
app/Models/Plugin.php (1)

262-265: ⚡ Quick win

Consider making the "no data" return values consistent.

Line 265 returns null when update_url is not set, while line 282 now returns [] when an exception occurs. Both represent "no update data available" but use different values. For better type consistency and predictability, consider either:

  • Returning [] in both cases and changing the return type annotation to array, or
  • Explicitly documenting why these cases use different return values

The downstream methods handle both correctly since they check truthiness, but consistent return values improve maintainability and type safety.

♻️ Proposed refactor for consistency
-    /** `@return` null|array<string, array{version: string, download_url: string}> */
-    private function getUpdateData(): ?array
+    /** `@return` array<string, array{version: string, download_url: string}> */
+    private function getUpdateData(): array
     {
         if (!$this->update_url) {
-            return null;
+            return [];
         }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/Models/Plugin.php` around lines 262 - 265, getUpdateData currently
returns null when $this->update_url is falsy but returns [] on exceptions,
causing inconsistent "no data" return values; change getUpdateData to always
return an array (use [] instead of null) and update the method signature/return
type annotation from ?array to array, ensuring callers still handle empty arrays
as "no update data" (refer to getUpdateData, $this->update_url and the exception
return), and update any docblocks or tests expecting null accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@app/Models/Plugin.php`:
- Around line 262-265: getUpdateData currently returns null when
$this->update_url is falsy but returns [] on exceptions, causing inconsistent
"no data" return values; change getUpdateData to always return an array (use []
instead of null) and update the method signature/return type annotation from
?array to array, ensuring callers still handle empty arrays as "no update data"
(refer to getUpdateData, $this->update_url and the exception return), and update
any docblocks or tests expecting null accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 247695bb-7d2b-4b69-acb5-38101441845b

📥 Commits

Reviewing files that changed from the base of the PR and between 2a328a2 and 5a22f26.

📒 Files selected for processing (1)
  • app/Models/Plugin.php

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.

1 participant