From a0f3e99b2dc46b441c1a1db09eaf6338f1c5298a Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 5 Nov 2022 10:25:14 +1100 Subject: [PATCH] feat(watcher): tear down watcher on failue, warning the user (#1707) --- lua/nvim-tree/watcher.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lua/nvim-tree/watcher.lua b/lua/nvim-tree/watcher.lua index df29e7bc..54bb9bd7 100644 --- a/lua/nvim-tree/watcher.lua +++ b/lua/nvim-tree/watcher.lua @@ -54,7 +54,8 @@ function Event:start() local event_cb = vim.schedule_wrap(function(err, filename) if err then - log.line("watcher", "event_cb for %s fail : %s", self._path, err) + log.line("watcher", "event_cb '%s' '%s' FAIL : %s", self._path, filename, err) + self:destroy(string.format("File system watcher failed (%s) for path %s, halting watcher.", err, self._path)) else log.line("watcher", "event_cb '%s' '%s'", self._path, filename) for _, listener in ipairs(self._listeners) do @@ -83,10 +84,14 @@ function Event:remove(listener) end end -function Event:destroy() +function Event:destroy(message) log.line("watcher", "Event:destroy '%s'", self._path) if self._fs_event then + if message then + utils.notify.warn(message) + end + local rc, _, name = self._fs_event:stop() if rc ~= 0 then notify.warn(string.format("Could not stop the fs_event watcher for path %s : %s", self._path, name))