Skip to content

fix: guard paginated fetchers against non-array API responses - #242

Open
pranayr710 wants to merge 1 commit into
AOSSIE-Org:mainfrom
pranayr710:fix/pagination-non-array-guard
Open

pranayr710 wants to merge 1 commit into
AOSSIE-Org:mainfrom
pranayr710:fix/pagination-non-array-guard

Conversation

@pranayr710

Copy link
Copy Markdown

Fixes #225

Problem

fetchRepos, fetchContributors, fetchIssues and fetchPulls all spread the response body directly into their accumulator:

const data = await fetchWithCache(url, pat)
all.push(...data)

Several GitHub API endpoints return a JSON object instead of an array under valid, non-error conditions:

  • issues disabled on a repository → { "message": "Issues are disabled in this repository" }
  • an empty repository → { "message": "Git Repository is empty." } or 204 No Content
  • a restricted repository → a warning/error payload object

When data is one of these, all.push(...data) throws TypeError: data is not iterable, which aborts the whole fetch — including any pages already collected — instead of degrading gracefully.

Fix

Treat a non-array page as an empty, final page: if (!Array.isArray(data)) break before the spread, in all four functions.

1 file changed (+7), plus a new test file.

Verification

Added src/services/github.pagination.test.js: mocks fetch to return the exact non-array payloads from the issue (a disabled-issues message, an empty-repo message) and asserts each of the four fetchers resolves to [] instead of throwing, plus one control case confirming a normal array page still collects correctly.

Confirmed the test fails against the unpatched code with the exact error from the issue (TypeError: Spread syntax requires ...iterable[Symbol.iterator] to be a function), and passes with the fix. Full suite: 49/49 passing (6 files).

Note

I found this issue unclaimed — no maintainer or reporter statement of intent to fix it — and built the patch directly given the volume of open issues here. Happy to adjust scope or close if a maintainer is already working this.

fetchRepos, fetchContributors, fetchIssues and fetchPulls spread the
response body directly: all.push(...data). Several GitHub API endpoints
return a JSON object instead of an array under valid conditions -
issues disabled on a repo, an empty repository, or a 204 No Content
response - and the spread throws TypeError: data is not iterable,
aborting the whole fetch instead of returning what was already
collected.

Treat a non-array page as an empty, final page: stop pagination there
rather than crash.

Fixes AOSSIE-Org#225
@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 59 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: Repository: AOSSIE-Org/OrgExplorer/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 3ed6aa18-85d3-4ba3-9a1e-4d624aac74d6

📥 Commits

Reviewing files that changed from the base of the PR and between 0b1110e and 1f4cd0a.

📒 Files selected for processing (2)
  • src/services/github.js
  • src/services/github.pagination.test.js

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.

@github-actions github-actions Bot added bug Something isn't working javascript JavaScript/TypeScript changes tests Test changes size/M 51-200 lines changed first-time-contributor First time contributor labels Sep 19, 2026
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/M 51-200 lines changed tests Test changes

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

1 participant