Skip to content

Fix: Handle empty database path when current directory is invalid#8

Open
echobt wants to merge 1 commit intomainfrom
fix/issue-44-empty-db-path-clean
Open

Fix: Handle empty database path when current directory is invalid#8
echobt wants to merge 1 commit intomainfrom
fix/issue-44-empty-db-path-clean

Conversation

@echobt
Copy link
Copy Markdown
Contributor

@echobt echobt commented Jan 19, 2026

Summary

Fixes a bug where the server API crashes or behaves unexpectedly when the current directory cannot be determined, leading to an empty database path.

Problem

When std::env::current_dir() fails, config.db_path() returns an error. The current implementation in �pi.rs uses .unwrap_or_default() which results in an empty path string. This is passed to Database::new(), potentially causing initialization failures or creating/accessing a database at an invalid location.

Solution

Explicitly handle the Result from config.db_path() in status and search endpoints. If the path cannot be determined, return a 500 Internal Server Error with a descriptive message instead of silently falling back to a default empty path.

Testing

  • Verified code compilation (fix is logic-based standard error handling).
  • The change ensures that failure to determine context results in a clear error rather than undefined behavior.

Related Issue

Fixes PlatformNetwork/bounty-challenge#44

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.

[BUG] Server API uses empty database path when current directory is invalid

1 participant