Skip to content

Fix GitHub API crashes on non-array responses (#225) - #227

Open
dhruvv16-hash wants to merge 2 commits into
AOSSIE-Org:mainfrom
dhruvv16-hash:fix-github-api-non-array
Open

Fix GitHub API crashes on non-array responses (#225)#227
dhruvv16-hash wants to merge 2 commits into
AOSSIE-Org:mainfrom
dhruvv16-hash:fix-github-api-non-array

Conversation

@dhruvv16-hash

@dhruvv16-hash dhruvv16-hash commented Sep 9, 2026

Copy link
Copy Markdown

Hey everyone! 👋

The Problem:
In src/services/github.js, paginated results are merged using the spread operator (all.push(...data)). When the GitHub API returns a non-array response (such as an error object, or a 202 Accepted status object, or an empty repository payload), the spread syntax throws a TypeError: data is not iterable, crashing the application.

The Fix:
I added a if (!Array.isArray(data)) break; guard inside the pagination loops for fetchRepos, fetchContributors, fetchIssues, and fetchPulls. Now, if a non-array response is received, the loop safely terminates and returns the valid array of items collected so far, preventing any crashes.

Fixes #225

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability when loading repositories, contributors, issues, and pull requests by safely handling unexpected or malformed responses.
    • Prevented page-loading errors caused by invalid response data.

Copilot AI lite review requested due to automatic review settings September 9, 2026 19:43
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Warning

Review limit reached

Next included review available in 54 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 5d04af5b-0bfc-467d-98ae-937c9dc33936

📥 Commits

Reviewing files that changed from the base of the PR and between 0853c45 and f5fb3b3.

📒 Files selected for processing (1)
  • src/services/github.js

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: abe79ab8-43e7-45ea-998b-c3e4171d62ec

📥 Commits

Reviewing files that changed from the base of the PR and between 0860ebe and 0853c45.

📒 Files selected for processing (1)
  • src/services/github.js

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

The paginated GitHub fetch functions now stop processing when fetchWithCache returns a non-array response. This prevents spreading malformed API responses into the aggregate result array.

Changes

GitHub pagination handling

Layer / File(s) Summary
Response array guards
src/services/github.js
fetchRepos, fetchContributors, fetchIssues, and fetchPulls break their pagination loops before appending non-array responses.

Priority: ⬆️ High

Estimated code review effort: 1 (Trivial) | ~3 minutes

Change: Bug fix · Severity of issue fixed: High

Merge Risk: ⚪ Minimal · up to 0853c

GitHub pagination now returns collected valid items instead of crashing on non-array responses. The change is narrowly scoped and ready to merge.

Suggested reviewers: ri1tik

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The guards fix the reported TypeError for non-array responses in the pagination functions [#225]. However, the linked issue also requires fetchWithCache to handle 204 No Content responses. The changes… Update fetchWithCache to detect 204 No Content or empty responses and return an empty array before calling res.json(). Add coverage for this case and for non-array API payloads.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: preventing crashes when GitHub API responses are not arrays.
Out of Scope Changes check ✅ Passed The changes are limited to pagination response validation in src/services/github.js. The fetchRepos guard is related defensive handling and is not unrelated to the linked issue.
Full details: Linked Issues check

Explanation

The guards fix the reported TypeError for non-array responses in the pagination functions [#225]. However, the linked issue also requires fetchWithCache to handle 204 No Content responses. The changes do not address res.json() failures for empty responses.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

A rabbit checks each page with care
No broken payloads scatter there
Arrays hop into the result stack
Error-shaped pages stop the track
The GitHub path stays calm and neat

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

@github-actions github-actions Bot added bug Something isn't working javascript JavaScript/TypeScript changes size/XS 1-10 lines changed first-time-contributor First time contributor labels Sep 9, 2026
@github-actions github-actions Bot added size/XS 1-10 lines changed and removed size/XS 1-10 lines changed labels Sep 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

fetchWithCache() can still throw on 204 No Content (and can cache 202 placeholder payloads), so crashes/incorrect early termination can still occur before the new array guards run.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR aims to prevent OrgExplorer’s GitHub pagination helpers from crashing when the GitHub API returns a non-array JSON payload by guarding the spread merge operations.

Changes:

  • Added Array.isArray guards before all.push(...data) in fetchRepos, fetchContributors, fetchIssues, and fetchPulls.
  • Pagination loops now terminate safely when a non-array response is encountered, returning items collected so far.
File summaries
File Description
src/services/github.js Adds array-type guards in pagination loops to avoid TypeError: data is not iterable when API payloads aren’t arrays.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/services/github.js
Comment on lines 93 to 96
const url = `https://api.github.com/orgs/${org}/repos?per_page=100&page=${page}&sort=updated`
const data = await fetchWithCache(url, pat)
if (!Array.isArray(data)) break
all.push(...data)
@github-actions github-actions Bot added size/XS 1-10 lines changed and removed size/XS 1-10 lines changed labels Sep 9, 2026
@gitcordapp

gitcordapp Bot commented Sep 9, 2026

Copy link
Copy Markdown

Link your account with Gitcord

Thanks for opening this PR, @dhruvv16-hash!

To receive Discord notifications and contributor tracking for this organization:

  1. Join Discord: https://discord.gg/hjUhu33uAn
  2. In Discord, run /link dhruvv16-hash
  3. Paste the verification code into your GitHub bio (or a public gist)
  4. Click Verify in Discord (or run /verify-link dhruvv16-hash)

Once linked, Gitcord can notify you about reviews, merges, and more.

Posted by Gitcord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working first-time-contributor First time contributor javascript JavaScript/TypeScript changes size/XS 1-10 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: fetchContributors, fetchIssues, and fetchPulls crash with "TypeError: data is not iterable" when GitHub API returns non-array objects

2 participants