Skip to content

[BUG] Empty Search Query Accepted #66

@eureka0928

Description

@eureka0928

Project

vgrep

Description

The search command accepts empty strings and whitespace-only queries without validation. This wastes computational resources generating embeddings for meaningless input and returns no useful results without explanation.

Error Message

$ vgrep search ""
# No output, no results, no error

$ vgrep search "   "
# No output, no results, no error

$ vgrep ""
# No output, no results, no error

Debug Logs

System Information

OS: Ubuntu 24.04.3 LTS
CPU: Intel(R) Core(TM) i9-14900HX (8 cores)
RAM: 16 GB

Screenshots

No response

Steps to Reproduce

  1. Index a codebase: vgrep index .
  2. Run vgrep search ""
  3. Observe command completes without error
  4. Observe no results returned and no explanation

Expected Behavior

  • Empty and whitespace-only queries rejected before processing
  • Clear error: "Error: Search query cannot be empty"
  • No resources wasted on meaningless embeddings

Actual Behavior

  • Empty query accepted and processed through embedding pipeline
  • Embedding model invoked with empty/whitespace string
  • Search completed with zero results
  • No indication that query was invalid

Additional Context

Added query validation in run_search_smart() in src/cli/commands.rs:

pub async fn run_search_smart(query: &str, config: &Config, max_results: usize) -> Result<()> {
    let query = query.trim();
    if query.is_empty() {
        ui::print_error("Search query cannot be empty");
        return Ok(());
    }

    // ... rest of search logic
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingvalidValid issuevgrep

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions