Prevent invalid JSONPath in message preview from crashing page#1870
Prevent invalid JSONPath in message preview from crashing page#1870khanhx wants to merge 1 commit into
Conversation
|
AI Summary A JSONPath expression in a message preview filter could cause the entire Messages page to crash if it threw an error during evaluation, and the invalid filter persisted in local storage made the crash recur on every reload. The fix wraps JSONPath evaluation in a try-catch within Message.tsx, so invalid expressions now display "Invalid JSONPath" inline without crashing the page. This allows the rest of the message row and page to render normally, providing graceful degradation for bad filters. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughMessage component adds an error-safe JSONPath evaluation helper that catches exceptions during filter evaluation and returns fallback error strings. The render logic uses this helper instead of direct JSONPath calls, preventing crashes when stored filters contain invalid expressions. A new test verifies the component remains stable when displaying invalid JSONPath errors. ChangesInvalid JSONPath Filter Handling
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Hi khanhx! 👋
Welcome, and thank you for opening your first PR in the repo!
Please wait for triaging by our maintainers.
Please take a look at our contributing guide.
| }; | ||
|
|
||
| const evaluateFilter = (path: string, json: unknown) => { | ||
| // A stored preview filter can hold an invalid JSONPath (e.g. saved before |
What & why
Closes #1436
When a message preview filter holds a JSONPath that errors at evaluation time (e.g. a filter expression that dereferences an undefined property such as
$[?(@.foo.bar.baz)]),JSONPath(...)is called directly insiderenderFilteredJsonduring render. The thrown error propagates out of render and crashes the whole Messages page.Because preview filters are persisted in local storage (
message-preview), the crash is sticky: it reproduces on every reload until the user manually clears that local-storage key. The existing validation inPreviewModalonly checks a path against an empty object ({}), so an expression that is structurally valid but throws against real message data, or any value saved before that validation existed, still gets through.Change
JSONPathevaluation inMessage.tsxin a guarded helper. On error it rendersInvalid JSONPathinline for that filter instead of throwing, so a single bad filter degrades gracefully and the rest of the row/page keeps working.Testing
Message.spec.tsxasserting that a stored filter with an invalid JSONPath renders the inline error and does not crash the row.pnpm jest Message.spec.tsx→ 13/13 passing.eslint --max-warnings=0clean on the changed files.Repro (before)
$[?(@.foo.bar.baz)]on a topic's Messages view.message-previewis removed from local storage.After this change the filter cell shows
Invalid JSONPathand the page stays usable.Summary by CodeRabbit
Release Notes
Bug Fixes
Tests