fix: add error handling for WebSocket message parsing#1025
fix: add error handling for WebSocket message parsing#1025himanshp1656 wants to merge 2 commits into
Conversation
Previously, if JSON.parse failed on an incoming WebSocket message, it would throw an unhandled exception. This change wraps the parsing in a try-catch block and emits a 'socket-error' event with details about the parse failure, allowing applications to handle malformed messages gracefully. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Hi, and thanks for contributing! Note: If you are part of Qlik: Before we can handle your pull request we need you to sign our contributor license agreement. And it only takes a few minutes! Here are some useful links to get you started: Having troubles? Feel free to reach out to us either here or on Slack! Note: Once the CLA is sorted, you should rebase/touch this pull request to trigger an update of this CLA status. |
Add tests to verify that: - Malformed JSON emits socket-error event with parse-error type - No uncaught exception is thrown when receiving invalid JSON Co-authored-by: Cursor <cursoragent@cursor.com>
|
Hi, and thanks for contributing! Note: If you are part of Qlik: Before we can handle your pull request we need you to sign our contributor license agreement. And it only takes a few minutes! Here are some useful links to get you started: Having troubles? Feel free to reach out to us either here or on Slack! Note: Once the CLA is sorted, you should rebase/touch this pull request to trigger an update of this CLA status. |
Here's a full PR description for your contribution:
Summary
This PR adds error handling for WebSocket message parsing in the
RPC.onMessagemethod to gracefully handle malformed JSON responses.Problem
When calling
getFullPropertyTree()on Qlik Sense objects (specifically sheets) that contain Vizlib Advanced Text Objects with HTML content including special characters, the WebSocket response fails to parse with the following error:Expected Behavior
The
getFullPropertyTree()method should either:Actual Behavior
The JSON parsing error occurs in the WebSocket communication layer and crashes the application. The error is not propagated as a catchable JavaScript error, making it impossible to handle gracefully in application code.
Root Cause
The
RPC.onMessagemethod callsJSON.parse()directly without any error handling:When QIX Engine returns a response containing control characters (e.g., from HTML content in Vizlib objects),
JSON.parse()throws aSyntaxErrorthat bubbles up and crashes the application.Solution
This PR wraps the
JSON.parse()call in a try-catch block and emits asocket-errorevent when parsing fails:Benefits
socket-erroreventsocket-errorevent listeners will work seamlesslyUsage Example
Test Plan
socket-errorevent is emitted with correct payload on parse failureRelated Issues
This addresses scenarios where third-party Qlik Sense extensions (like Vizlib) store HTML content with special/control characters in object properties, causing
getFullPropertyTree()and similar methods to fail.Would you like me to adjust anything in this PR description?