Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

fs.watch() crash #3250

Closed
llafuente opened this issue May 10, 2012 · 3 comments
Closed

fs.watch() crash #3250

llafuente opened this issue May 10, 2012 · 3 comments

Comments

@llafuente
Copy link

Here is the test to reproduce the crash (at least on windows XP)

var fs = require('fs');

function listener() {
    console.log("listener", arguments);
}

fs.watch("c://test", listener);
fs.mkdirSync("c:/test/new-path");
fs.watch("c:/test/new-path", listener);
fs.rmdirSync("c:/test/new-path");

Execution:

listener { '0': 'rename', '1': 'new-path' }
events.js:48
      throw arguments[1]; // Unhandled 'error' event
                     ^
Error: watch EPERM
  at errnoException (fs.js:648:11)
  at FSEvent.onchange (fs.js:662:26)

What I expect
A)

 listener { '0': 'rename', '1': 'new-path' }
 listener { '0': 'rename', '1': null } <-- detect the delete and unwatch

B)

Dont crash, maybe a new event to the callback so we can be notified of the error

Thanks :)

@piscisaureus
Copy link

You can handle the error. However the directory isn't automatically unwatched and I consider that a bug.

var watcher = fs.watch('c:\\test\\new-dir');
watcher.on('error', function(e) {
  watcher.close();
});

@llafuente
Copy link
Author

Thanks for the quick fix :)

1 similar comment
@llafuente
Copy link
Author

Thanks for the quick fix :)

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

No branches or pull requests

2 participants