Skip to content

Requiring directories that contain broken symlinks throws an error #27

@lxe

Description

@lxe

If a directory contains a broken symlink at any level of its subdirectory tree, performing require-directoty() in it will always throw an ENOENT error.

For example, running index.js in the following tree:

├── dir
│   └── broken-subdir -> nonexistent
├── index.js

Where the contents of index.js is just require('require-directory')(module) will throw:

$ node index.js

fs.js:696
  return binding.stat(pathModule._makeLong(path));
                 ^
Error: ENOENT, no such file or directory '/Users/aleksey/require-directotry-test/dir/broken-subdir'
    at Object.fs.statSync (fs.js:696:18)
    at /Users/aleksey/require-directotry-test/node_modules/require-directory/index.js:65:12
    at Array.forEach (native)
    at requireDirectory (/Users/aleksey/require-directotry-test/node_modules/require-directory/index.js:59:24)
    at /Users/aleksey/require-directotry-test/node_modules/require-directory/index.js:67:15
    at Array.forEach (native)
    at requireDirectory (/Users/aleksey/require-directotry-test/node_modules/require-directory/index.js:59:24)
    at Object.<anonymous> (/Users/aleksey/require-directotry-test/index.js:1:91)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)

I think it should still attempt to traverse and load the successful directories, and defer the error handling to the consumer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions