#16112: fix: add error handler to memory file watcher to prevent crashes
stale
size: XS
trusted-contributor
Cluster:
Skill Enhancements and Fixes
## Summary
The chokidar file watcher in `ensureWatcher()` was missing an error handler, which could cause unhandled errors when filesystem race conditions occur (e.g., when folders are created during active conversations). This fix adds a proper error handler that logs the error instead of crashing.
## Changes
- Added `watcher.on("error", ...)` handler to the memory file watcher in `src/memory/manager-sync-ops.ts`
## Testing
- All 91 memory-related unit tests pass
- The fix follows the same pattern used in `config-reload.ts` and `refresh.ts`
Fixes openclaw/openclaw#16070
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Added error handler to memory file watcher in `ensureWatcher()` method to prevent unhandled promise rejections when filesystem race conditions occur. The fix follows established patterns from `config-reload.ts:361-368` and `refresh.ts:179-181` where similar chokidar watchers log errors rather than crashing the application.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The change is a defensive programming fix that adds proper error handling to prevent crashes. It follows the exact same pattern used consistently throughout the codebase for chokidar watchers, uses appropriate logging, and has no logical flaws or breaking changes
- No files require special attention
<sub>Last reviewed commit: 4ef851a</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#6362: fix(memory): add ignore patterns to chokidar file watcher
by Glucksberg · 2026-02-01
75.5%
#17647: fix: Display error messages instead of (no output) for non-Claude m...
by MisterGuy420 · 2026-02-16
72.8%
#14023: fix: filter skills watcher to relevant file types to prevent FD exh...
by funmerlin · 2026-02-11
70.7%
#17896: fix(config): warn instead of silently swallowing chmod failure on c...
by PlayerGhost · 2026-02-16
70.4%
#4386: fix(memory): persist dirty flag to prevent false positive on status
by Iamadig · 2026-01-30
69.8%
#22327: fix(doctor): use gateway health status for memory search key check
by therk · 2026-02-21
69.6%
#18029: infra: fix memory leak and error handling in event listeners
by MAhmadUzair · 2026-02-16
69.6%
#21240: fix: GH#20607 prevent doctor from dropping custom config sections
by theognis1002 · 2026-02-19
69.5%
#17463: fix: write config files with explicit 0o600 mode instead of post-wr...
by miclaldogan · 2026-02-15
69.4%
#11101: fix: handle AbortError and WebSocket 1006 in unhandled rejection ha...
by Nipurn123 · 2026-02-07
69.2%