Skip to content

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

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions