floatdrop / gulp-watch

Watch, that actually is an endless stream
MIT License
643 stars 99 forks source link

Occasionally crashes with Atom's temporary files. #238

Open ghost opened 8 years ago

ghost commented 8 years ago

Seems to occasionally crash on a temporary files created by the "Backup before saving" option in Atom. Getting the following error:

events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: ENOENT: no such file or directory, stat '/Users/keironlowe/Development/removed/removed/removed/expressionengine/templates/stash/partials/blocks/views/navigation.html~'

Disabling the option fixes the error for me but it's not ideal. Issue also opened on the Atom repo.

UltCombo commented 8 years ago

I think this is a problem in Chokidar and/or gulp-watch; it is missing some error handling at some point(s).

You see, once the watcher fires an event, we add a delay before reading the file contents. It is possible that the file no longer exists by then. It should be possible to reproduce the issue even without a delay, as external file system changes (e.g. deleting files) may happen at any time during script execution.

Not sure what's the best approach, maybe we can catch the error and don't fire the callback for added/changed files when they have been removed before we could read them.

UltCombo commented 8 years ago

By the way, I believe you can temporarily workaround the issue by ignoring the backup files, e.g.:

watch(['files/**/*', '!files/**/*~'])
UltCombo commented 8 years ago

Actually, I believe you should always ignore the backup files—you most likely don't want them to be processed by gulp. So, my comment above is the correct fix for your specific case, but we can keep this issue open to improve our error handling.

UltCombo commented 8 years ago

242 has been merged into this issue.

If anyone is interested in contributing with a patch, here's some useful info: https://github.com/floatdrop/gulp-watch/issues/242#issuecomment-230209702