yuanchuan / node-watch

A wrapper and enhancements for fs.watch
https://npm.im/node-watch
MIT License
339 stars 44 forks source link

Catch errors when adding watchers for child directories #108

Closed maksis closed 2 years ago

maksis commented 3 years ago

I got the following crash (node-watch 0.7.1) when attempting to watch Program files recursively on Ubuntu Bash for Windows:

Error: EACCES: permission denied, watch '/mnt/c/Program Files (x86)/Google/CrashReports'
    at FSWatcher.<computed> (internal/fs/watchers.js:218:26)
    at Object.watch (fs.js:1525:34)
    at fn (/package/dist/webpack:/airdcpp-share-monitor/node_modules/node-watch/lib/watch.js:397:22)
    at hasNativeRecursive (/package/dist/webpack:/airdcpp-share-monitor/node_modules/node-watch/lib/has-native-recursive.js:61:12)
    at b.watchDirectory (/package/dist/webpack:/airdcpp-share-monitor/node_modules/node-watch/lib/watch.js:380:3)
    at fn (/package/dist/webpack:/airdcpp-share-monitor/node_modules/node-watch/lib/watch.js:413:16)
    at forEach (/package/dist/webpack:/airdcpp-share-monitor/node_modules/node-watch/lib/watch.js:142:35)

The same crash also happens when the system limit for maximum watches is reached (ENOSPC).

Looks like the errors aren't caught when the library iterates recursively over subdirectories and calls fs.watch for each of them. Could watcher's error handler be called in such cases?

yuanchuan commented 3 years ago

You're right! The errors should be caught in the error callback