Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fs.watch error message includes filename
  • Loading branch information
charlierudolph committed Sep 30, 2015
commit 756bf4e9cf2edf34b785e69bfe2418026233600d
8 changes: 6 additions & 2 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,9 @@ function FSWatcher() {
this._handle.onchange = function(status, event, filename) {
if (status < 0) {
self._handle.close();
self.emit('error', errnoException(status, 'watch'));
const error = errnoException(status, `watch ${filename}`);
error.filename = filename;
self.emit('error', error);
} else {
self.emit('change', event, filename);
}
Expand All @@ -1234,7 +1236,9 @@ FSWatcher.prototype.start = function(filename, persistent, recursive) {
recursive);
if (err) {
this._handle.close();
throw errnoException(err, 'watch');
const error = errnoException(err, `watch ${filename}`);
error.filename = filename;
throw error;
}
};

Expand Down
17 changes: 17 additions & 0 deletions test/sequential/test-fs-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,20 @@ assert.throws(function() {
w.stop();
}, TypeError);
oldhandle.stop(); // clean up

assert.throws(function() {
fs.watch('non-existent-file');
}, function(err) {
assert(err);
assert(/non-existent-file/.test(err));
assert.equal(err.filename, 'non-existent-file');
return true;
});

var watcher = fs.watch(__filename);
watcher.on('error', common.mustCall(function(err) {
assert(err);
assert(/non-existent-file/.test(err));
assert.equal(err.filename, 'non-existent-file');
}));
watcher._handle.onchange(-1, 'ENOENT', 'non-existent-file');