mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
fix: handle FileNotFoundError gracefully during sync
When a file exists in the database but is missing from the filesystem, the sync worker now treats this as a deletion instead of crashing. The sync_file() method catches FileNotFoundError specifically and calls handle_delete() to clean up the orphaned database record. This prevents the sync from failing on database/filesystem inconsistencies that can occur due to race conditions, manual file deletions, or cloud storage caching issues. Includes a test to verify the graceful handling behavior. Fixes #386 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: phernandez <paul@basicmachines.co>
This commit is contained in:
@@ -610,6 +610,16 @@ class SyncService:
|
||||
)
|
||||
return entity, checksum
|
||||
|
||||
except FileNotFoundError:
|
||||
# File exists in database but not on filesystem
|
||||
# This indicates a database/filesystem inconsistency - treat as deletion
|
||||
logger.warning(
|
||||
f"File not found during sync, treating as deletion: path={path}. "
|
||||
"This may indicate a race condition or manual file deletion."
|
||||
)
|
||||
await self.handle_delete(path)
|
||||
return None, None
|
||||
|
||||
except Exception as e:
|
||||
# Check if this is a fatal error (or caused by one)
|
||||
# Fatal errors like project deletion should terminate sync immediately
|
||||
|
||||
Reference in New Issue
Block a user