[BUG]: `fetchWithCache` crashes with `SyntaxError: Unexpected end of JSON input` when encountering empty repositories (HTTP 204 No Content)

未关闭 适合新手
#433 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 4 天内回复

@Devnil434 已经在做这个了。

开始于 2026年10月29日。

  • #434 来自 @Devnil434 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
76/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
github, javascript
领域
api, backend

调研方向

从 src/services/github.js 中的 fetchWithCache 及其调用方 fetchContributors、fetchRepos、fetchIssues 和 fetchPulls 开始。检查代码如何处理成功的 204 No Content 响应,以及调用方数据是否可迭代;使用空 repository 的 contributors endpoint 重现问题。当探索包含空 repository 的组织时,不再出现已报告的 JSON 解析或迭代错误,即为完成。

由索引模型根据 Issue 内容生成。

描述

bug
Bug Description

When analyzing a GitHub organization that contains empty repositories (repositories with zero commits or no contributor activity), GitHub's REST API endpoint (GET /repos/{owner}/{repo}/contributors) returns an HTTP 204 No Content status code with an empty response body.

In src/services/github.js, fetchWithCache treats any response where res.ok is true (status 200–299) as JSON and attempts to parse it via await res.json():

// src/services/github.js (Lines 78-82)
if (!res.ok) throw new Error(`HTTP_${res.status}`)

const data = await res.json()
cacheSet(url, data)
return data

Because res.status === 204 has no body, calling res.json() throws an unhandled:

SyntaxError: Unexpected end of JSON input

Furthermore, in caller functions such as fetchContributors, fetchRepos, fetchIssues, and fetchPulls, the return value is spread directly into an array without verifying that data is an array:

// src/services/github.js (Lines 106-108)
const data = await fetchWithCache(url, pat)
all.push(...data)
if (data.length < 100) break

If data is empty, null, or not an array, spreading ...data throws an unhandled:

TypeError: data is not iterable

This causes exploration to fail or drop repositories when analyzing organizations that have placeholder, archived, or newly initialized empty repositories.


Steps to Reproduce
  1. Open OrgExplorer home page.
  2. Search for any GitHub organization that contains one or more empty repositories (e.g., an org with newly created repos that have no commits pushed).
  3. Click EXPLORE (or run complete analysis with a PAT).
  4. Open browser DevTools Console.
  5. Notice the uncaught SyntaxError: Unexpected end of JSON input when fetching contributors for the empty repo.

Logs and Screenshots
GET https://api.github.com/repos/{org}/{empty-repo}/contributors?per_page=100&page=1 204 (No Content)

Uncaught (in promise) SyntaxError: Unexpected end of JSON input
    at fetchWithCache (github.js:80)
    at async fetchContributors (github.js:106)
    at async AppContext.jsx:120

Uncaught (in promise) TypeError: data is not iterable
    at fetchContributors (github.js:107)

Environment Details
  • OS: Windows 11 / macOS / Linux
  • Browser: Google Chrome, Mozilla Firefox, Safari
  • Component: src/services/github.js (fetchWithCache, fetchContributors, fetchRepos, fetchIssues, fetchPulls)

Impact

Critical - Application is unusable

Code of Conduct
  • I have joined the Discord server and will post updates there
  • I have searched existing issues to avoid duplicates
主要语言
JavaScript
星标
48
派生
163
平均合并
4 天 13 小时
30 天内合并 PR
25

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

AOSSIE-Org/OrgExplorer 的其他 Issue

查看 AOSSIE-Org/OrgExplorer 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。