Skip to content

Prevent invalid JSONPath in message preview from crashing page#1870

Open
khanhx wants to merge 1 commit into
kafbat:mainfrom
khanhx:fix/messages-invalid-jsonpath-crash
Open

Prevent invalid JSONPath in message preview from crashing page#1870
khanhx wants to merge 1 commit into
kafbat:mainfrom
khanhx:fix/messages-invalid-jsonpath-crash

Conversation

@khanhx

@khanhx khanhx commented Jun 3, 2026

Copy link
Copy Markdown

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 inside renderFilteredJson during 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 in PreviewModal only 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

  • Wrap the per-filter JSONPath evaluation in Message.tsx in a guarded helper. On error it renders Invalid JSONPath inline for that filter instead of throwing, so a single bad filter degrades gracefully and the rest of the row/page keeps working.

Testing

  • Added a unit test in Message.spec.tsx asserting 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=0 clean on the changed files.

Repro (before)

  1. Add a preview filter with path $[?(@.foo.bar.baz)] on a topic's Messages view.
  2. The page crashes; reloading keeps crashing until message-preview is removed from local storage.

After this change the filter cell shows Invalid JSONPath and the page stays usable.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed a crash on the messages page that occurred when filters contained invalid expressions. The page now gracefully displays an error message for problematic filters instead of crashing.
  • Tests

    • Added test coverage for handling invalid message filters.

@khanhx khanhx requested a review from a team as a code owner June 3, 2026 12:30
@kapybro kapybro Bot added status/triage/manual Manual triage in progress and removed status/triage/manual Manual triage in progress labels Jun 3, 2026
@kapybro

kapybro Bot commented Jun 3, 2026

Copy link
Copy Markdown

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.

@kapybro kapybro Bot changed the title fix(messages): prevent invalid JSONPath preview filter from crashing the page Prevent invalid JSONPath in message preview from crashing page Jun 3, 2026
@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 008a4e85-35aa-4e24-bf23-2a665986b864

📥 Commits

Reviewing files that changed from the base of the PR and between 82f8419 and 29d09ea.

📒 Files selected for processing (2)
  • frontend/src/components/Topics/Topic/Messages/Message.tsx
  • frontend/src/components/Topics/Topic/Messages/__test__/Message.spec.tsx

📝 Walkthrough

Walkthrough

Message 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.

Changes

Invalid JSONPath Filter Handling

Layer / File(s) Summary
Error-safe filter evaluation helper and usage
frontend/src/components/Topics/Topic/Messages/Message.tsx
evaluateFilter wraps JSONPath evaluation in try/catch to return 'Invalid JSONPath' string on error. Per-filter rendering now uses evaluateFilter instead of direct JSONPath(...) call, preventing exceptions from propagating during component render.
Test coverage for invalid filter rendering
frontend/src/components/Topics/Topic/Messages/__test__/Message.spec.tsx
New test renders the message table with a malformed JSONPath in contentFilters and verifies the component displays the error message without crashing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A JSONPath that breaks the day,
Now caught and rendered safe in gray,
No more crashes from stored mistakes,
Just error text the filter makes! 📋✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: preventing invalid JSONPath expressions in message previews from crashing the page.
Linked Issues check ✅ Passed The code changes address the core requirement from issue #1436 by wrapping JSONPath evaluation in error handling and displaying inline error messages instead of crashing.
Out of Scope Changes check ✅ Passed All changes are directly related to preventing invalid JSONPath crashes: the helper function in Message.tsx and corresponding test coverage are within scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kapybro kapybro Bot added area/messages scope/frontend Related to frontend changes type/bug Something isn't working labels Jun 3, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

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.

please remove this ai prose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/messages scope/frontend Related to frontend changes type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FE: Messages: JSON path errors crash the page

2 participants