Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requiring directories that contain broken symlinks throws an error #27

Open
lxe opened this issue Aug 2, 2016 · 1 comment
Open

Requiring directories that contain broken symlinks throws an error #27

lxe opened this issue Aug 2, 2016 · 1 comment

Comments

@lxe
Copy link

lxe commented Aug 2, 2016

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.

@Rycochet
Copy link

I've come across a similar error where it decides to get relative paths wrong - but using fs.resolve(path) on the path before handing it over fixes that before it gets here. It's only related in that the error could do with being in user-land. Didn't track down the "why" hence not opening a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants