fix: guard paginated fetchers against non-array API responses - #242
Open
pranayr710 wants to merge 1 commit into
Open
pranayr710 wants to merge 1 commit into
pranayr710 wants to merge 1 commit into
Conversation
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
|
Warning Review limit reachedNext included review available in 59 minutes. View limit detailsLimit 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. Review configuration: ⚙️ Run configurationConfiguration used: Repository: AOSSIE-Org/OrgExplorer/.coderabbit.yaml Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (2)
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. Comment |
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.
Fixes #225
Problem
fetchRepos,fetchContributors,fetchIssuesandfetchPullsall spread the response body directly into their accumulator:Several GitHub API endpoints return a JSON object instead of an array under valid, non-error conditions:
{ "message": "Issues are disabled in this repository" }{ "message": "Git Repository is empty." }or204 No ContentWhen
datais one of these,all.push(...data)throwsTypeError: 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)) breakbefore the spread, in all four functions.1 file changed (+7), plus a new test file.
Verification
Added
src/services/github.pagination.test.js: mocksfetchto 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.