isaacs / isexe

Minimal module to check if a file is executable.
ISC License
48 stars 17 forks source link

Throwing too many exceptions on windows #12

Open BurtHarris opened 7 years ago

BurtHarris commented 7 years ago

Using fs.stat or fs.statSync on windows ends up throwing lots of exceptions.

For example (one of hundreds generated by running a gulp command.

Exception has occurred: Error
Error: ENOENT: no such file or directory, stat 'c:\code\antlr4ts\npm.COM'
at Object.fs.statSync (fs.js:940:11)
at Function.sync (c:\code\antlr4ts\node_modules\isexe\windows.js:41:23)
at Function.sync (c:\code\antlr4ts\node_modules\isexe\index.js:49:17)
at Function.whichSync [as sync] (c:\code\antlr4ts\node_modules\which\which.js:117:20)
at npmPath (c:\code\antlr4ts\node_modules\global-prefix\index.js:67:45)
at Object.<anonymous> (c:\code\antlr4ts\node_modules\global-prefix\index.js:30:15)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
Gudahtt commented 6 years ago

That error indicates that the path does not exist. Throwing an error makes sense in that case.

The ignoreErrors option might be what you're looking for. This will test whether or not a file is executable, but return false if any error is encountered. This is useful for files that might not exist. There is an example of this in the README.