fix: clarify raw FTS query errors - #43
Conversation
|
Warning Review limit reached
Next review available in: 41 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughRaw FTS5 query errors are standardized in the core search library and applied to CLI history and event searches. CLI help now documents raw MATCH syntax, with tests covering quoted literals and friendly malformed-query errors. ChangesRaw FTS5 error handling
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/ai-hist-core/src/lib.rs`:
- Around line 474-482: Restrict raw_fts_query_error to convert only confirmed
SQLite FTS5 MATCH syntax errors into the user-facing malformed-query message;
return the original error for all other SQLite and decoding failures. In
crates/ai-hist-core/src/lib.rs lines 547-552, preserve both mappings while
ensuring non-FTS query and collection errors propagate; apply the narrowed
conversion to history searches at crates/ai-hist/src/lib.rs lines 2594-2597 and
event searches at lines 2636-2639.
In `@crates/ai-hist/src/lib.rs`:
- Around line 4983-5005: Expand malformed_raw_fts_query_has_a_friendly_error to
cover every affected search path: retain the SearchRole::All assertion, add a
SearchRole::Assistant case to exercise the event-row branch after history lookup
succeeds, and add a direct core search invocation with raw_fts enabled. Apply
the same friendly-error and exclusion assertions to each case, reusing the
existing query setup.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a89db227-aaf4-4458-816d-8d07a0281933
📒 Files selected for processing (2)
crates/ai-hist-core/src/lib.rscrates/ai-hist/src/lib.rs
The first pass converted every rusqlite error into the malformed-expression message whenever raw mode was on, so I/O, decoding and genuine schema errors during a raw search were relabelled as FTS5 syntax problems. That traded one bad error surface for a worse one. is_fts5_syntax_error() now identifies actual FTS5 parse failures (messages naming fts5, malformed match, unterminated string, or the 'no such column' bareword misparse); everything else propagates untouched. Test expanded to cover SearchRole::All, SearchRole::Assistant (the event-row branch reached after history lookup succeeds) and a direct ai_hist_core::search call with raw_fts enabled, via a shared assert_friendly_fts_error helper.
|
Both findings were valid and are fixed in 1. Error mapping was too broad — real bug, thanksThe first pass discarded the original error whenever Now narrowed: fn is_fts5_syntax_error(error: &rusqlite::Error) -> bool {
let rusqlite::Error::SqliteFailure(_, Some(message)) = error else {
return false;
};
let m = message.to_ascii_lowercase();
m.contains("fts5")
|| m.contains("malformed match")
|| m.contains("unterminated string")
|| m.starts_with("no such column")
}
I considered interpolating the underlying error into the friendly message for diagnosability, but the existing assertions require raw SQLite text to stay out of user-facing output, and your finding was about masking non-FTS errors rather than surfacing FTS ones. Kept the message clean and let the predicate do the work. 2. Test coverage expanded
Verification
I also mutation-checked the test rather than trusting a green run — forcing So the assertion is genuinely load-bearing on the narrowing, not just on the message text. Live CLI, unchanged semantics confirmed: |
Summary
FTS escaping was not broken:
quote_fts_termalready quotes and escapes non-raw terms, including hyphenated input. The actual issue was that--ftsexplicitly passes its input through as a raw FTS5MATCHexpression, where FTS5 interprets operators such as-.This documents that raw-mode contract and maps malformed raw FTS5 expressions to an actionable error. Raw mode remains unescaped and unchanged.
Verification
. "$HOME/.cargo/env" && cargo build— passed. "$HOME/.cargo/env" && cargo test --workspace— passed (58 unit tests)GATE_FAIL parity:🤖 Generated with Claude Code