Skip to content

Fix: Add proper error handling for db_path in server API#2

Open
echobt wants to merge 1 commit intomainfrom
fix/issue-36-db-path-error-handling
Open

Fix: Add proper error handling for db_path in server API#2
echobt wants to merge 1 commit intomainfrom
fix/issue-36-db-path-error-handling

Conversation

@echobt
Copy link
Copy Markdown
Contributor

@echobt echobt commented Jan 19, 2026

Summary

This PR adds explicit error handling for database path resolution failures in the server API endpoints.

Problem

The status() and search() endpoints in src/server/api.rs were using state.config.db_path().unwrap_or_default() to obtain the database path. When db_path() fails (which returns Result), unwrap_or_default() silently converts the error into an empty PathBuf.

This is problematic because:

  • SQLite may interpret an empty path as a request for an in-memory database
  • User data could be lost without any indication of failure
  • Search operations may return empty results with no error message
  • The actual cause of the failure is completely hidden from the user

Solution

Replaced unwrap_or_default() with explicit error handling using match expressions. When db_path() fails, the API now:

  • Returns HTTP 500 Internal Server Error status code
  • Provides a descriptive error message including the underlying failure reason
  • Prevents any attempt to open a database with an invalid path

The changes affect:

  • Line 146: status() endpoint
  • Line 231: search() endpoint

Testing

The fix has been verified by code review. The changes ensure proper error propagation follows the same pattern used elsewhere in the codebase for other error conditions.

Related Issue

Fixes PlatformNetwork/bounty-challenge#36

echobt added a commit that referenced this pull request Jan 19, 2026
…main--components--term-challenge

chore(main): release 0.1.0
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] Database Path Silently Falls Back to Invalid Path

1 participant