Skip to content

Unsafe JSON Parsing Leads to entire application will crash (White Screen of Death).#299

Open
aniket866 wants to merge 1 commit intoAOSSIE-Org:mainfrom
aniket866:fixed-json-parsing
Open

Unsafe JSON Parsing Leads to entire application will crash (White Screen of Death).#299
aniket866 wants to merge 1 commit intoAOSSIE-Org:mainfrom
aniket866:fixed-json-parsing

Conversation

@aniket866
Copy link

@aniket866 aniket866 commented Feb 7, 2026

Added json parsing in Try catch block , see issue

    if (savedState) {
      try {
        return JSON.parse(savedState);
      } catch (error) {
        console.error("Failed to parse saved debate state:", error);
        // Optional: clear the corrupted state so it doesn't persist
        localStorage.removeItem(debateKey);
        return defaultState;
      }
    }
    
return defaultState;

});
Closes #300

@bhavik-mangla Please review , can be merged, let me know any issue
Thankyou

Summary by CodeRabbit

  • Bug Fixes
    • Improved debate room initialization to gracefully handle corrupted locally stored data, preventing crashes and automatically recovering to default settings while logging errors for troubleshooting.

@coderabbitai
Copy link

coderabbitai bot commented Feb 7, 2026

📝 Walkthrough

Walkthrough

Refactors DebateRoom state initialization by introducing a centralized defaultState object to replace inline defaults and adding robust JSON parsing with try/catch error handling to manage corrupted localStorage data gracefully.

Changes

Cohort / File(s) Summary
State Initialization Refactoring
frontend/src/Pages/DebateRoom.tsx
Centralizes default state values in a dedicated object and adds error handling for corrupted localStorage JSON parsing, automatically clearing invalid data and falling back to defaults.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 With defaults now gathered in ordered array,
And corrupted whispers swept clean away,
The DebateRoom state shines fresh and bright,
No more tangled data, just initialized right!
A rabbit's delight—robust and neat. 🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main change: adding error handling for unsafe JSON parsing to prevent application crashes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

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.

Unsafe JSON Parsing Leads to entire application will crash (White Screen of Death).

1 participant