Skip to content

[BUG] Database Path Silently Falls Back to Invalid Path #36

@olddev94

Description

@olddev94

Project

vgrep

Description

The server API in src/server/api.rs lines 146 and 231 uses state.config.db_path().unwrap_or_default() which silently falls back to an empty PathBuf if db_path() fails. SQLite will interpret an empty path as either an in-memory database or fail in unexpected ways, causing data loss or search failures.

Error Message

No error message - silent incorrect behavior leading to empty search results or data loss.

Debug Logs

System Information

- Bounty Version: 0.1.0
- OS: Ubuntu 24.04 LTS
- Rust: 1.75+

Screenshots

No response

Steps to Reproduce

  1. Set $HOME environment variable to an invalid/inaccessible path
  2. Start vgrep server: vgrep serve
  3. Index some files: vgrep index
  4. Search: vgrep "query"
  5. Observe empty results because writes went to wrong database

Expected Behavior

If db_path() fails, the server should:

  1. Return a proper error response (500 Internal Server Error)
  2. Log the failure reason
  3. NOT silently fall back to an invalid path

Actual Behavior

When db_path() fails:

  1. unwrap_or_default() returns empty PathBuf
  2. SQLite may create/use an in-memory database or a file named "" in current directory
  3. User data is lost or searches return empty results
  4. No indication of the problem

Additional Context

The same pattern should be audited throughout the codebase. Any unwrap_or_default() on a Result<PathBuf> is suspicious and should be replaced with proper error handling.

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