Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Watchr (2.4.0) fails on broken links #42

Closed
jagill opened this Issue · 3 comments

2 participants

James Gill Benjamin Arthur Lupton
James Gill

In general I like how this library works, but it errors out with ENOENT when it encounters a broken link. It doesn't pass an error to the callback, but rather throws an exception, which is a bit harder to handle. It happens both on initial scan, and if you add a broken link later.

It seems there are a few (non mutually exclusive) solutions to this:
1. When reading a file, does a check that fs.realpath exists, and skips if not.
2. If it catches a ENOENT, it tries to use fs.lstat instead of fs.stat.
3. There's a option followLinks:false that can be passed that uses fs.lstat all of the time, instead of fs.stat.

If you'd like a PR for 3, I'll see what i can do. Since broken links occur all the time with OS X, and with emacs, it's a significant issue for my application.

I'm on OS X 10.8.3, and below is the output of npm --versions:

{ http_parser: '1.0',
  node: '0.8.21',
  v8: '3.11.10.25',
  ares: '1.7.5-DEV',
  uv: '0.8',
  zlib: '1.2.3',
  openssl: '1.0.0f',
  npm: '1.2.11',
  'watchr-bug': '0.0.1' }

Below is the output when i run watchr in a directory containing a broken link.

watching the path /Users/jag/projects/watchr-bug failed with error { [Error: ENOENT, stat '/Users/jag/projects/watchr-bug/broken']
  errno: 34,
  code: 'ENOENT',
  path: '/Users/jag/projects/watchr-bug/broken' }
a log message occured: { '0': 'debug',
  '1': 'Preferred method failed, trying methods in reverse order',
  '2': 
   { [Error: ENOENT, stat '/Users/jag/projects/watchr-bug/broken']
     errno: 34,
     code: 'ENOENT',
     path: '/Users/jag/projects/watchr-bug/broken' } }
a log message occured: { '0': 'debug', '1': 'watch: /Users/jag/projects/watchr-bug' }
a log message occured: { '0': 'debug', '1': 'close: /Users/jag/projects/watchr-bug' }
watching the path /Users/jag/projects/watchr-bug failed with error { [Error: ENOENT, stat '/Users/jag/projects/watchr-bug/broken']
  errno: 34,
  code: 'ENOENT',
  path: '/Users/jag/projects/watchr-bug/broken' }
watching everything failed with error { [Error: ENOENT, stat '/Users/jag/projects/watchr-bug/broken']
  errno: 34,
  code: 'ENOENT',
  path: '/Users/jag/projects/watchr-bug/broken' }
Benjamin Arthur Lupton
Owner

Thanks for the real detailed report, definitely can see it could be an issue for a lot of people.

Could you do this up as a pull request, I'll happily review and merge :)

James Gill

Hmm.. Some problems lie pretty deep in the dependencies. For example, balUtils.rmdirDeep dies on broken links, because it first recursively scans the directory (which involves statting each file), then tries to delete it. This means that it can't delete a directory with a broken link, and in fact deletes a directory with a whole lot of extra overhead (statting each object).

I'll first put in a PR with safefs to allow an lstat function, which will be useful for these things.

Additionally, the tests in watchr error out on cleanup due to the balUtils.rmdirDeep issue. Is there a reason you use those methods as opposed to the standard (and quick and safe) ryanmcgrath/wrench-js or the efficient isaacs/rimraf? balUtils could be patched to use the the safefs lstat fn.

Once these are done the actual PR for watchr can be done.

FredrikNoren FredrikNoren referenced this issue in FredrikNoren/ungit
Closed

Watchr sometimes crashes with ENOENT error #36

James Gill jagill referenced this issue in bevry/safefs
Merged

Adding lstat function. #1

FredrikNoren FredrikNoren referenced this issue from a commit
FredrikNoren Optionally use lstat. #42
Introduces a new config variable as suggested in #42.
da058a7
Benjamin Arthur Lupton balupton referenced this issue from a commit
Benjamin Arthur Lupton v2.4.7. Bugfix.
- v2.4.7 December 19, 2013
	- Fixed: [Text Editor swap files on saving can throw it off](#33)
	- Fixed: [`ENOENT` errors are emitted when dead links a broken symlink is encountered](#42)
	- Updated dependencies
90d089f
Benjamin Arthur Lupton
Owner

Can everyone try again with watchr v2.4.7. Will re-open if it is still an issue.

Benjamin Arthur Lupton balupton closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.