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

Đang mở Phù hợp với người mới
#433 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 4 ngày

@Devnil434 đang làm issue này rồi.

Từ ngày 29/10/2026.

  • #434 của @Devnil434 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
76/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
github, javascript
Lĩnh vực
api, backend

Hướng nghiên cứu

Bắt đầu tại src/services/github.js, ở fetchWithCache và các hàm gọi fetchContributors, fetchRepos, fetchIssues và fetchPulls. Kiểm tra cách mã xử lý phản hồi thành công 204 No Content và liệu dữ liệu của hàm gọi có thể lặp qua được hay không; tái hiện bằng endpoint contributors của một repository trống. Hoàn tất khi việc khám phá một tổ chức có các repository trống kết thúc mà không gặp lỗi phân tích JSON hoặc lỗi lặp đã được báo cáo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
JavaScript
Star
48
Fork
163
Merge trung bình
5 ngày 2 giờ
Pull request đã merge (30 ngày)
31

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của AOSSIE-Org/OrgExplorer

Tất cả issue của AOSSIE-Org/OrgExplorer

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.