Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throws errors when filesystem changes during Hound.prototype.watch #5

Open
cspotcode opened this issue Jan 17, 2013 · 3 comments
Open
Labels

Comments

@cspotcode
Copy link

If a file is created and then deleted before Hound.prototype.watch has a chance to execute, then Hound will attempt to stat a non-existent file. All other fs operations run by Hound can also fail under similar circumstances.

I was able to throw in some try-catches to fix the problem but a proper solution depends on what kind of guarantees you want to make about Hound's behavior.

If Hound must report all FS changes, however temporary, then you've got a problem. If a file is created and then deleted before Hound can stat the file, it'll have to fire a 'create' event without any stat data, followed by a 'delete' event.

It's easier if you only require Hound to fire enough events that an observer arrives at a valid view of the eventual steady-state of the filesystem. In other words, if a file is created and then immediately deleted, Hound doesn't need to fire any events. "oops, it was too fast." Of course, if a file is created and remains extant then Hound is required to fire a 'created' event. If the file is modified twice in quick succession, Hound can get away with firing only one 'change' event, provided that event fires after the second file change has completed. For my personal use-case (automatically rebuilding templates & recompiling code as I edit them) this is totally fine.

@beefsack
Copy link
Collaborator

Hi @cspotcode, sorry about the delay getting back to you, I'll look at this one this week.

@huttj
Copy link

huttj commented Dec 31, 2014

Any updates on this?

I, too, managed to work around it with a couple of try/catch blocks--one around the body of the watch method, and one around the create event on hound.js:70.

I needed those because fs was throwing errors when WebStorm would very rapidly create and delete temporary files with ___jb_bak___ and ___jb_old___ suffixes, which it couldn't catch in time. I was using it to watch a directory.

@cspotcode
Copy link
Author

IIRC, it was the exact same situation for me: WebStorm / IntelliJ quickly creating and deleting files.

@huttj For what it's worth, there are other file-watcher libraries you can consider using. Gaze is depended on by grunt-contrib-watch and many other grunt plugins so it's probably a good choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants