From 05be4a2729ecedb8f8c6e8d677e3d0c5566b5ba4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 4 Apr 2026 02:58:15 +0000 Subject: [PATCH 1/2] fix: guard against TopDocs::with_limit(0) panic in all call sites 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> --- src/index/reader.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/index/reader.rs b/src/index/reader.rs index 5d913ec..44fa3f1 100644 --- a/src/index/reader.rs +++ b/src/index/reader.rs @@ -137,8 +137,11 @@ impl IndexReader { } else { sq.offset.saturating_add(sq.limit) }; - let (top_docs, _) = - searcher.search(&combined, &(TopDocs::with_limit(fetch_count), Count))?; + let (top_docs, _) = if fetch_count == 0 { + (vec![], 0) + } else { + searcher.search(&combined, &(TopDocs::with_limit(fetch_count), Count))? + }; let mut all_results: Vec = top_docs .into_iter() @@ -181,10 +184,14 @@ impl IndexReader { (sliced, pre_filter_count) } else { // Search mode: let Tantivy handle offset/limit with relevance ranking - let (top_docs, total_count) = searcher.search( - &combined, - &(TopDocs::with_limit(sq.limit).and_offset(sq.offset), Count), - )?; + let (top_docs, total_count) = if sq.limit == 0 { + (vec![], searcher.search(&combined, &Count)?) + } else { + searcher.search( + &combined, + &(TopDocs::with_limit(sq.limit).and_offset(sq.offset), Count), + )? + }; let results: Vec = top_docs .into_iter() .map(|(_score, addr)| { @@ -332,6 +339,9 @@ impl IndexReader { }; let total = searcher.search(&query, &Count)?; + if total == 0 { + return Ok((vec![], matched_gavs)); + } let top_docs = searcher.search(&query, &TopDocs::with_limit(total))?; let mut pkg_counts: BTreeMap = BTreeMap::new(); @@ -374,6 +384,9 @@ impl IndexReader { let query = BooleanQuery::new(clauses); let total = searcher.search(&query, &Count)?; + if total == 0 { + return Ok((vec![], gavs.iter().map(|s| s.to_string()).collect())); + } let top_docs = searcher.search(&query, &TopDocs::with_limit(total))?; let mut pkg_counts: BTreeMap = BTreeMap::new(); From 8b089912d9f46c7b5803c80e077a7c5b2a5ec1c8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 4 Apr 2026 03:03:13 +0000 Subject: [PATCH 2/2] fix: return empty matched_gavs when total is 0 in list_packages_for_gavs 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> --- src/index/reader.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index/reader.rs b/src/index/reader.rs index 44fa3f1..90ac347 100644 --- a/src/index/reader.rs +++ b/src/index/reader.rs @@ -385,7 +385,7 @@ impl IndexReader { let query = BooleanQuery::new(clauses); let total = searcher.search(&query, &Count)?; if total == 0 { - return Ok((vec![], gavs.iter().map(|s| s.to_string()).collect())); + return Ok((vec![], vec![])); } let top_docs = searcher.search(&query, &TopDocs::with_limit(total))?;