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);
}
recursive);
if (err) {
this._handle.close();
- throw errnoException(err, 'watch');
+ const error = errnoException(err, `watch ${filename}`);
+ error.filename = filename;
+ throw error;
}
};
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');