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
- Set
$HOME environment variable to an invalid/inaccessible path
- Start vgrep server:
vgrep serve
- Index some files:
vgrep index
- Search:
vgrep "query"
- Observe empty results because writes went to wrong database
Expected Behavior
If db_path() fails, the server should:
- Return a proper error response (500 Internal Server Error)
- Log the failure reason
- NOT silently fall back to an invalid path
Actual Behavior
When db_path() fails:
unwrap_or_default() returns empty PathBuf
- SQLite may create/use an in-memory database or a file named "" in current directory
- User data is lost or searches return empty results
- 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.
Project
vgrep
Description
The server API in
src/server/api.rslines 146 and 231 usesstate.config.db_path().unwrap_or_default()which silently falls back to an emptyPathBufifdb_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
Debug Logs
System Information
Screenshots
No response
Steps to Reproduce
$HOMEenvironment variable to an invalid/inaccessible pathvgrep servevgrep indexvgrep "query"Expected Behavior
If
db_path()fails, the server should:Actual Behavior
When
db_path()fails:unwrap_or_default()returns emptyPathBufAdditional Context
The same pattern should be audited throughout the codebase. Any
unwrap_or_default()on aResult<PathBuf>is suspicious and should be replaced with proper error handling.