Skip to content

fix: guard against malformed/non-array history data in fetchUserInfo#261

Merged
jagdish-15 merged 1 commit into
codepvg:mainfrom
Tamcodes4:fix/malformed-history-array-guard
Jun 28, 2026
Merged

fix: guard against malformed/non-array history data in fetchUserInfo#261
jagdish-15 merged 1 commit into
codepvg:mainfrom
Tamcodes4:fix/malformed-history-array-guard

Conversation

@Tamcodes4

@Tamcodes4 Tamcodes4 commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes a crash in fetch-user-info.js when historical user data is malformed. The endpoint now gracefully falls back to an empty history array instead of throwing an error when the fetched JSON is null or contains a non-array history field.

Linked Issue

Fixes #239

Changes Made

  • Added a null/object check before accessing migrated profile fields.
  • Added a defensive Array.isArray(history) guard before sorting historical data.
  • Preserved the existing migration logic for both legacy array-based and new object-based profile formats.
  • Prevented history.sort() from throwing when malformed history data is encountered.

Type of Change

  • Bug fix
  • New feature
  • UI/Visual update
  • Documentation update
  • Refactor

Testing

  • Tested locally
  • Tested on mobile viewport (if applicable)
  • No console errors introduced

Test Cases

Verified the following scenarios locally:

  • Valid legacy history array
  • Valid object-based profile structure
  • Empty object ({})
  • null
  • { "history": "corrupted" }
  • { "history": {} }

Confirmed that malformed history data now degrades gracefully to an empty history array instead of causing the /api/user/:username endpoint to fail.

Checklist

  • My code follows the project's coding style
  • I have formatted my code locally by running npx prettier --write . before submitting
  • I am submitting my PR from a dedicated feature/* branch, not the main branch
  • I have performed a self-review of my code
  • My changes generate no new warnings or errors
  • I have updated documentation if required
  • I have linked the relevant issue

Screenshots / Screen Recording

N/A, Backend robustness fix with no UI changes.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for submitting a pull request.

Please ensure your changes comply with the project's contribution guidelines and that all workflow checks pass successfully.

Formatting and Branching

  • Please confirm you have formatted your code locally using npx prettier --write . before requesting a review.
  • Ensure this PR is made from a feature/* branch and not main.

Note: This project is currently maintained by a solo maintainer, so reviews and responses may sometimes take a little time. Thanks for your patience.

@Tamcodes4

Copy link
Copy Markdown
Contributor Author

Hey @jagdish-15, could you review this pr?

@jagdish-15 jagdish-15 added type:bug Something isn't working level:beginner Indicates the difficulty gssoc:approved quality:clean labels Jun 28, 2026
@jagdish-15 jagdish-15 merged commit 2121c32 into codepvg:main Jun 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved level:beginner Indicates the difficulty quality:clean type:bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] /api/user/:username can return 500 if historical data file isn't a valid array

2 participants