Skip to content

fix: crashes caused by invalid saved layout JSON and show toasts for recovery - #1560

Merged
vedansh-5 merged 12 commits into
fossasia:devfrom
tonypzy:fix/main-json-parse-safety
Jul 31, 2026
Merged

fix: crashes caused by invalid saved layout JSON and show toasts for recovery#1560
vedansh-5 merged 12 commits into
fossasia:devfrom
tonypzy:fix/main-json-parse-safety

Conversation

@tonypzy

@tonypzy tonypzy commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds defensive JSON parsing (safeJsonParse) to handle malformed JSON and prevent frontend runtime exceptions.

Motivation and Context

The following malformed JSON cases are now safely handled by safeJsonParse:

localStorage.setItem('envIDs', '["main", "demo"'); # Truncated JSON
localStorage.setItem('layout_main_pane_1', 'undefined'); # Non-JSON text
localStorage.setItem('layout_main_pane_1', '{x: 0, y: 0}'); # Invalid object syntax
localStorage.setItem('envIDs', ''); # Empty persisted value

How Has This Been Tested?

Check code manually

Screenshots (if appropriate):

N/A

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code refactor or cleanup (changes to existing code for improved readability or performance)

Checklist:

  • I adapted the version number under py/visdom/VERSION according to Semantic Versioning
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry @tonypzy, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@tonypzy

tonypzy commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

@Debajeet-1411

Copy link
Copy Markdown
Contributor

@tonypzy Nice improvement. Consider adding a Cypress test for malformed localStorage JSON to verify the recovery path and guard against future regressions.

@Debajeet-1411 Debajeet-1411 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One potential edge case came to mind—I've left an inline comment with the details.

Comment thread js/main.js
@tonypzy

tonypzy commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

@tonypzy Nice improvement. Consider adding a Cypress test for malformed localStorage JSON to verify the recovery path and guard against future regressions.

cytest is not meant for handling such trivial cases. it is primarily designed to verify higher-level functionality, such as plotting features and screenshot pixel comparisons.

@tonypzy

tonypzy commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

@tonypzy Nice improvement. Consider adding a Cypress test for malformed localStorage JSON to verify the recovery path and guard against future regressions.

Or we can add to pytest #1543

@Debajeet-1411

Copy link
Copy Markdown
Contributor

@tonypzy Thanks for the clarification. That makes sense-this is better suited as a unit test than an end-to-end Cypress test.

@rajnisht7 rajnisht7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@tonypzy it works good in ui but what about adding info for the same

@Manik-Khajuria-5 Manik-Khajuria-5 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@tonypzy I agree with @rajnisht7 idea of adding in the ui section also

@tonypzy
tonypzy requested a review from rajnisht7 July 26, 2026 04:59
@tonypzy

tonypzy commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

@tonypzy it works good in ui but what about adding info for the same

This is the toast effect.
image

@tonypzy tonypzy changed the title Fix crashes caused by invalid saved layout JSON Fix crashes caused by invalid saved layout JSON and show toasts for recovery Jul 26, 2026

@Saksham-Sirohi Saksham-Sirohi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copilot flagged the following:

  • No blocking issues.

@tonypzy tonypzy changed the title Fix crashes caused by invalid saved layout JSON and show toasts for recovery fix: crashes caused by invalid saved layout JSON and show toasts for recovery Jul 30, 2026
@vedansh-5
vedansh-5 merged commit ba52767 into fossasia:dev Jul 31, 2026
15 checks passed
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.

7 participants