Skip to content

fix: guard against TopDocs::with_limit(0) panic - #2

Draft
rscarrera27 with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-limit-check-in-collector
Draft

fix: guard against TopDocs::with_limit(0) panic#2
rscarrera27 with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-limit-check-in-collector

Conversation

Copilot AI commented Apr 4, 2026

Copy link
Copy Markdown

Summary / 요약

tantivy::TopDocs::with_limit(0) panics at runtime. This is reachable from 4 call sites in src/index/reader.rs — whenever a Count query returns 0 results or the caller passes limit=0.

thread 'main' panicked at tantivy-0.25.0/src/collector/top_collector.rs:85:9:
Limit must be strictly greater than 0.

Repro: cpsurf search pkg "im.toss.teamhome.serialization" on a dependency with no matching documents.

Fix: Early-return empty results when the limit would be 0, at all 4 sites:

  • list_packages_for_dependencyCount returns 0 → return (vec![], matched_gavs)
  • list_packages_for_gavsCount returns 0 → return (vec![], vec![])
  • search() listing mode — offset + limit is 0 → return empty (vec![], 0)
  • search() search mode — sq.limit is 0 → skip TopDocs, still return Count

Checklist / 체크리스트

  • cargo fmt -- --check passes / 통과
  • cargo clippy -- -D warnings passes / 통과
  • cargo test passes / 통과
  • If index schema changed: reader/writer are synchronized / 인덱스 스키마 변경 시: reader/writer 동기화 완료
  • If new subcommand added: Commands enum updated, main.rs match arm added / 새 서브커맨드 추가 시: Commands enum 업데이트, main.rs match arm 추가

Copilot AI and others added 2 commits April 4, 2026 02:58
When tantivy's Count collector returns 0, or when search limit is 0,
return empty results early instead of passing 0 to TopDocs::with_limit()
which panics with "Limit must be strictly greater than 0".

Agent-Logs-Url: https://github.com/rscarrera27/classpath-surfer/sessions/53c88d62-0211-453e-ad3d-e59ebcc0599b

Co-authored-by: rscarrera27 <20695897+rscarrera27@users.noreply.github.com>
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.

2 participants