Skip to content

Commit 464e85d

Browse files
committed
Throw explicit error message about bad input
1 parent bf23c07 commit 464e85d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

index.js

+9
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,10 @@ FSWatcher.prototype.add = function(paths, _origAdd, _internal) {
474474
this.closed = false;
475475
paths = flatten(arrify(paths));
476476

477+
if (!paths.every(isString)) {
478+
throw new TypeError('Non-string provided as watch path');
479+
}
480+
477481
if (cwd) paths = paths.map(function(path) {
478482
if (isAbsolute(path)) {
479483
return path;
@@ -581,6 +585,11 @@ function importHandler(handler) {
581585
importHandler(NodeFsHandler);
582586
if (FsEventsHandler.canUse()) importHandler(FsEventsHandler);
583587

588+
// little isString util for use in Array.prototype.every
589+
function isString(maybeString) {
590+
return typeof maybeString === 'string'
591+
}
592+
584593
// Export FSWatcher class
585594
exports.FSWatcher = FSWatcher;
586595

0 commit comments

Comments
 (0)