Expands MathJs error handling #3486
Open
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.



PR Summary
Overview
This PR improves formula error handling in the spreadsheet view by ensuring all MathJS formula errors are properly displayed to users. Previously, generic errors were silently ignored, making it difficult to debug formula issues.
Changes Made
Core Logic Updates (
column-mapper.ts)Added
isSingleSymbol()helper function: Uses MathJS parser to detect if a formula is a simple reference (e.g.,columnAorobject.property) versus a complex expressionEnhanced error handling:
Errorinstances: Returns new generic error message for complex formulasundefined(no error shown) to avoid flooding the UI with "missing data" errorscolumnAhas no value could be expected, whilecolumnA + columnB * 2failing indicates an actual problem that needs attention.Targeted error suppression: Only simple references are filtered out. Any computation, operation, or function call will still display errors, ensuring users see problems with their actual formulas.
Null safety improvement: Added check to only validate non-null results from
limitedEvaluate()to avoid displaying typing errors when the computed value is equal toundefinedTranslation Updates
Added new generic error message :
spreadsheet/formula/error/generic: "Formula returns an error" / "La formule renvoie une erreur"Solution Rationale
The chosen approach for filtering out missing data error was chosen over two alternatives:
Alternative 1: Parse Error Stack Strings to filter out targeted errors
Alternative 2: Remove
@NonNullLombok Annotations in BackendChosen Solution: Parse Formula Structure
The key improvement is using MathJS's AST parser to distinguish between simple data references and complex formulas. When a formula fails to evaluate, we parse it to determine if it's a single symbol (e.g.,
columnA) or accessor (e.g.,object.propertyobject.prop1['index']). If it is, we suppress the error and returnundefined, treating it as missing data rather than a formula error.Why this approach was chosen:
Frontend-only solution: Avoids backend changes that would impact payload size (+25% in tested datasets) and potentially break other application components expecting non-null guarantees.
Robust implementation: Uses MathJS's own parser rather than fragile string matching on error messages. The parser understands the formula structure, making the solution resilient to library updates and edge cases.
Performance: Parsing only occurs on error, so there's minimal overhead. The vast majority of successful formula evaluations bypass this logic entirely.
Going Further
A potential enhancement would be to add a per-column configuration option for error display behavior. This would allow users to choose between: