fix: prevent infinite loop from invalid diagnostic spans in code editor #192
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The code editor crashes with an infinite loop when typing specific expressions with boolean expected types.
Reproduction steps:
expectedVariableTypetotrue(boolean type)filter([], )in the editorRoot Cause
The crash is caused by invalid diagnostic span data returned from the WASM type checking system. Specifically, when the zen-engine-wasm performs type checking on the expression
filter([], )with a boolean expected type, it returns a diagnostic with:{ "from": 11, "to": 10, "severity": "warning", "message": "Invalid syntax at (10, 10)", "source": "Type check" }The invalid span where from > to (from: 11, to: 10) causes CodeMirror's internal diagnostic processing to enter an infinite loop.
Solution
Added validation in the validateZenExpression function to ensure diagnostic spans are always valid before passing them to CodeMirror:
This fix ensures that even if the WASM layer returns invalid spans, we create valid diagnostics that CodeMirror can process safely.
Testing