thecodrr / fdir

⚡ The fastest directory crawler & globbing library for NodeJS. Crawls 1m files in < 1s
https://thecodrr.github.io/fdir/
MIT License
1.51k stars 58 forks source link

Permission errors don't seem to be handled. #8

Closed OmgImAlexis closed 4 years ago

OmgImAlexis commented 4 years ago

Permission errors don't seem to be handled.

import * as fdir from 'fdir';

fdir.async('/', {}).then(files => {
    console.log(files);
});
TypeError: Cannot read property 'length' of undefined
    at /Users/xo/code/r/node_modules/fdir/index.js:40:39
    at fs.js:153:23
    at FSReqCallback.req.oncomplete (fs.js:778:9)

Changing the affected line to this.

        fs.readdir(dir, readdirOpts, function(_, dirents) {
          console.log({_,dirents});
          for (var j = 0; j < dirents.length; ++j) {

I get the following.

{
  _: [Error: EACCES: permission denied, scandir '//.fseventsd'] {
    errno: -13,
    code: 'EACCES',
    syscall: 'scandir',
    path: '//.fseventsd'
  },
  dirents: undefined
}
thecodrr commented 4 years ago

I am on it. Thanks for reporting.

OmgImAlexis commented 4 years ago

With that fix what happens if only one sub directory has a permission error but all others are fine?

thecodrr commented 4 years ago

It will reject, bailing out of the function. Should it simply skip over that directory? How will errors be handled then? We have two options:

  1. We save all errors in an array and at the end we reject the promise with those errors and the results.
  2. We resolve the promise but send errors with result too.