Skip to content

🐛 Bug Report: Contributors API Response Not Type-Validated #506

@Tanayajadhav1

Description

@Tanayajadhav1

📜 Description

📜 Description

The ContributorsPage component fetches GitHub repository contributors using the GitHub API but does not validate the response before using it. The code assumes the response always matches the expected Contributor[] structure, which introduces runtime risk.
Currently, the API response is directly assigned to state without any validation or error handling.

Problem:
This creates several reliability and safety issues:

  • No HTTP status validation: Error responses (404/403/429) may still be treated as valid data
  • Type safety bypass: TypeScript assumes response.data is Contributor[], but runtime data may differ
  • Runtime crashes: If response is not an array, .map() will break the component
  • Malformed data risk: Missing fields like avatar_url, html_url, or contributions can cause UI failures
  • API unpredictability: GitHub API can return error objects or change response structure without warning
  • Weak error handling: Generic catch block does not provide meaningful debugging information

Expected Behavior:
Before setting state, the application should:

  • Validate HTTP response status (response.status === 200)
  • Ensure response is an array of valid contributors
  • Verify required fields exist in each contributor object
  • Handle invalid responses gracefully
  • Show fallback UI when data is unavailable or corrupted

Affected Files:

  • src/pages/Contributors/Contributors.tsx
  • src/types/github.ts (optional)
  • src/utils/constants.ts (optional)

Suggested Implementation Approaches:

Option A: Manual Validation (No Dependencies)
Check response.status === 200
Add isContributorArray() type guard
Validate required fields before rendering

Option B: Zod Validation
Use shared schema with other API validations
Define ContributorSchema and ContributorsArraySchema
Validate using:
ContributorsArraySchema.parse(response.data)

Suggested Labels:
gssoc'26, level:intermediate, bug, type:fix

i would like to work on this issue under gssoc'26

What browsers are you seeing the problem on?

No response

📃 Relevant Screenshots (Links)

No response

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions