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

Improper handling of broken symlinks, causes UnhandledPromiseRejectionWarning #955

Closed
jaens opened this issue Nov 29, 2019 · 5 comments
Closed

Comments

@jaens
Copy link

jaens commented Nov 29, 2019

When watching a directory with followSymlinks off, if the directory contains links for which the target does not exist, chokidar blows up with:

UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, stat <path of symlink>

This is due to calling fsrealpath on the link, which fails (since the link target does not exist) here:

const linkPath = await fsrealpath(path);

Note the node.js documentation for fs.realpath:

Asynchronously computes the canonical pathname by resolving ., .. and symbolic links.

(it does not specify what happens when the link target does not exist, but as reality shows it throws ENOENT...)

Perhaps using the fs.readlink function would be more appropriate there.

@jaens
Copy link
Author

jaens commented Nov 29, 2019

Looks like fsrealpath is also being used in a similar manner here:

const targetPath = follow ? await fsrealpath(path) : path;

@rory-ye-nv
Copy link

same problem here

@paulmillr
Copy link
Owner

pull requests are welcome

@nicks
Copy link
Contributor

nicks commented Jun 1, 2020

fwiw, this breaks create-react-app's webpack server hard, because it treats these warnings as errors and crashes the server

The error looks like this:

/home/nick/src/tilt/web/node_modules/react-scripts/scripts/start.js:19
  throw err;
  ^

[Error: ENOENT: no such file or directory, stat '/home/nick/src/tilt/web/src/.#Statusbar.tsx'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'stat',
  path: '/home/nick/src/tilt/web/src/.#Statusbar.tsx'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Here's the stack trace to the call that throws the error.

    at internal/util.js:297:30
    at new Promise (<anonymous>)
    at internal/util.js:296:12
    at NodeFsHandler._handleSymlink (/home/nick/src/tilt/web/node_modules/watchpack/node_modules/chokidar/lib/nodefs-handler.js:433:30)
    at ReaddirpStream.<anonymous> (/home/nick/src/tilt/web/node_modules/watchpack/node_modules/chokidar/lib/nodefs-handler.js:486:23)
    at ReaddirpStream.emit (events.js:321:20)
    at addChunk (_stream_readable.js:294:12)
    at readableAddChunk (_stream_readable.js:275:11)
    at ReaddirpStream.Readable.push (_stream_readable.js:209:10)

I'm happy to send a PR, but is there some reason this isn't as simple as wrapping the unhandled await call in a try...catch block? I'm probably missing something.

@paulmillr
Copy link
Owner

try adding try catch, adding the failing test, and seeing if that breaks any other tests

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

No branches or pull requests

4 participants