Skip to content

Conversation

@edlsh
Copy link
Contributor

@edlsh edlsh commented Dec 28, 2025

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)

Ripgrep.search previously crashed with SyntaxError when ripgrep output
contained malformed JSON lines. This can happen due to corrupted output,
binary file detection messages, or interrupted streams.

Changes:
- Extract JSON parsing into parseJsonLines helper with try/catch
- Skip malformed lines instead of crashing, log warnings with context
- Use Result.safeParse for schema validation failures
- Add tests for malformed JSON handling
- Skip Ripgrep.search tests when rg unavailable to prevent network downloads
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant