Skip to content

fix(web): prevent Previous page crash on malformed localStorage JSON#644

Closed
Ashvin-KS wants to merge 1 commit into
AOSSIE-Org:mainfrom
Ashvin-KS:fix/previous-localstorage-json-guard
Closed

fix(web): prevent Previous page crash on malformed localStorage JSON#644
Ashvin-KS wants to merge 1 commit into
AOSSIE-Org:mainfrom
Ashvin-KS:fix/previous-localstorage-json-guard

Conversation

@Ashvin-KS
Copy link
Copy Markdown
Contributor

@Ashvin-KS Ashvin-KS commented Mar 29, 2026

Summary

  • guard last5Quizzes parsing in Previous.jsx with ry/catch
  • validate parsed payload is an array before using it
  • clear corrupted localStorage value and fall back to an empty quiz list

Why

The Previous page currently assumes last5Quizzes is always valid JSON. If the key is malformed, JSON.parse throws and the page crashes.

Fixes #643

Validation

pm --prefix eduaid_web run build (successful; existing unrelated lint warnings remain in the project)

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of corrupted quiz history data to prevent app crashes. The app now gracefully recovers when local storage contains invalid or malformed data, automatically clearing problematic entries and restoring functionality.

Copilot AI review requested due to automatic review settings March 29, 2026 12:03
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 29, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1e0118cb-82e7-45ba-93d6-ae9c42c8e573

📥 Commits

Reviewing files that changed from the base of the PR and between 2038116 and a4cd671.

📒 Files selected for processing (1)
  • eduaid_web/src/pages/Previous.jsx

📝 Walkthrough

Walkthrough

The getQuizzesFromLocalStorage function in the Previous page now defensively handles malformed or missing localStorage data. It wraps JSON parsing in a try/catch block, validates the result is an array, removes invalid data from storage, and returns an empty array on failure.

Changes

Cohort / File(s) Summary
Defensive localStorage handling
eduaid_web/src/pages/Previous.jsx
Enhanced getQuizzesFromLocalStorage with try/catch wrapping, array validation, and automatic cleanup of malformed last5Quizzes entries to prevent page crashes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A localStorage tale so bright,
Where broken JSON met its plight,
With catch blocks ready, defenses in place,
No crashes now—just a clean, safe space!
Previous page hops along just fine,
Error handling? Absolutely divine! 🌟

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Ashvin-KS
Copy link
Copy Markdown
Contributor Author

Closing this draft PR for now; I will resubmit using the required PR format/template.

@Ashvin-KS Ashvin-KS closed this Mar 29, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the Previous page against malformed last5Quizzes data in localStorage so the page no longer crashes when JSON.parse fails, aligning behavior with Issue #643’s expected graceful recovery.

Changes:

  • Wrap last5Quizzes parsing in try/catch to prevent JSON.parse from crashing the page.
  • Validate that the parsed payload is an array before using it.
  • Remove the corrupted localStorage key and fall back to an empty quiz list on invalid data.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Previous page crashes when last5Quizzes localStorage value is invalid JSON

2 participants