diff --git a/lib/file-list.js b/lib/file-list.js index 92e1f264f..1e17eba26 100644 --- a/lib/file-list.js +++ b/lib/file-list.js @@ -186,17 +186,22 @@ var List = function(patterns, excludes, emitter, preprocess) { pending++; matchedAndNotIgnored++; fs.stat(path, function(error, stat) { - if (!stat.isDirectory()) { - // TODO(vojta): reuse file objects - var file = new File(path, stat.mtime); - - preprocess(file, function() { - buckets[i].push(file); - finish(); - }); - } else { - log.debug('Ignored directory "%s"', path); + if (error) { + log.debug('An error occured while reading "%s"', path); finish(); + } else { + if (!stat.isDirectory()) { + // TODO(vojta): reuse file objects + var file = new File(path, stat.mtime); + + preprocess(file, function() { + buckets[i].push(file); + finish(); + }); + } else { + log.debug('Ignored directory "%s"', path); + finish(); + } } }); }); diff --git a/test/unit/file-list.spec.coffee b/test/unit/file-list.spec.coffee index 2fd88eb1f..37f382518 100644 --- a/test/unit/file-list.spec.coffee +++ b/test/unit/file-list.spec.coffee @@ -144,6 +144,15 @@ describe 'file-list', -> expect(files.served).to.exist done() + it 'should handle fs.stat errors', (done) -> + sinon.stub(mockFs, 'stat').yields([new Error(), null]) + list = new m.List patterns('/some/*.js'), [], emitter, preprocessMock + + refreshListAndThen (files) -> + mockFs.stat.restore() + done() + + #============================================================================ # List.reload()