[PR #6275] fix(ripgrep): handle malformed JSON lines gracefully in search results #11813

Open
opened 2026-02-16 18:16:45 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6275

State: open
Merged: No


Problem

Ripgrep.search crashes with SyntaxError: JSON Parse error when ripgrep outputs malformed JSON lines. This can happen due to:

  • Corrupted output
  • Binary file detection messages
  • Interrupted streams

Currently JSON.parse(line) is called without error handling, causing the entire search to fail on a single bad line.

Solution

Extract JSON parsing into a parseJsonLines helper with try/catch that:

  • Skips malformed JSON lines instead of crashing
  • Logs warnings with context (first 200 chars) for debugging
  • Uses Result.safeParse for schema validation failures
  • Returns only successfully parsed matches

Also skip Ripgrep.search tests when rg binary is unavailable to prevent network downloads during test runs.

Testing

bun test test/file/ripgrep.test.ts

All 8 tests pass:

  • 3 integration tests for Ripgrep.search (skipped if rg unavailable)
  • 5 unit tests for Ripgrep.parseJsonLines (always run)
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6275 **State:** open **Merged:** No --- ## Problem `Ripgrep.search` crashes with `SyntaxError: JSON Parse error` when ripgrep outputs malformed JSON lines. This can happen due to: - Corrupted output - Binary file detection messages - Interrupted streams Currently `JSON.parse(line)` is called without error handling, causing the entire search to fail on a single bad line. ## Solution Extract JSON parsing into a `parseJsonLines` helper with try/catch that: - Skips malformed JSON lines instead of crashing - Logs warnings with context (first 200 chars) for debugging - Uses `Result.safeParse` for schema validation failures - Returns only successfully parsed matches Also skip `Ripgrep.search` tests when `rg` binary is unavailable to prevent network downloads during test runs. ## Testing ```bash bun test test/file/ripgrep.test.ts ``` All 8 tests pass: - 3 integration tests for `Ripgrep.search` (skipped if rg unavailable) - 5 unit tests for `Ripgrep.parseJsonLines` (always run)
yindo added the pull-request label 2026-02-16 18:16:45 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11813