Skip to content

Commit d987aab

Browse files
committed
Catch errors when watching too many files and provide help. Closes #8
1 parent 2455d48 commit d987aab

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

index.js

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"use strict";
22

3-
let makeWatcher = require("nite-owl");
43
let path = require("path");
54

65
const PLUGINS = {
@@ -17,18 +16,7 @@ module.exports = (rootDir, config = "faucet.config.js", // eslint-disable-next-l
1716

1817
let watcher;
1918
if(watch) {
20-
let { watchDirs } = config;
21-
/* eslint-disable indent */
22-
watchDirs = watchDirs ?
23-
watchDirs.map(dir => path.resolve(configDir, dir)) :
24-
[configDir];
25-
/* eslint-enable indent */
26-
27-
let separator = watchDirs.length === 1 ? " " : "\n";
28-
console.error("monitoring file system at" + separator +
29-
watchDirs.join(separator));
30-
31-
watcher = makeWatcher(watchDirs);
19+
watcher = makeWatcher(config.watchDirs, configDir);
3220
}
3321

3422
Object.keys(PLUGINS).forEach(type => {
@@ -51,3 +39,30 @@ function load(pkg) {
5139
process.exit(1);
5240
}
5341
}
42+
43+
function makeWatcher(watchDirs, configDir) {
44+
let niteOwl = require("nite-owl");
45+
46+
/* eslint-disable indent */
47+
watchDirs = watchDirs ?
48+
watchDirs.map(dir => path.resolve(configDir, dir)) :
49+
[configDir];
50+
/* eslint-enable indent */
51+
52+
let separator = watchDirs.length === 1 ? " " : "\n";
53+
console.error("monitoring file system at" + separator + watchDirs.join(separator));
54+
55+
let watcher = niteOwl(watchDirs);
56+
watcher.on("error", err => {
57+
if(err.code === "ERR_TOO_MANY_FILES") {
58+
console.error("There are too many files being monitored, " +
59+
"please use the `watchDirs` configuration setting:\n" +
60+
// eslint-disable-next-line max-len
61+
"https://github.com/faucet-pipeline/faucet-pipeline#configuration-for-file-watching");
62+
process.exit(1);
63+
}
64+
65+
throw err;
66+
});
67+
return watcher;
68+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"dependencies": {
2626
"minimist": "^1.2.0",
27-
"nite-owl": "^3.1.0"
27+
"nite-owl": "^3.2.0"
2828
},
2929
"devDependencies": {
3030
"eslint": "^4.4.1",

0 commit comments

Comments
 (0)