facebook / facebook/watchman

[nodejs] cannot handle error when watchman is not installed

Open
#509 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
13.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

[From the docs:](https://facebook.github.io/watchman/docs/nodejs.html#checking-for-watchman-availability)

```js
var watchman = require('fb-watchman');
var client = new watchman.Client();
client.capabilityCheck({optional:[], required:['relative_root']},
function (error, resp) {
if (error) {
// error will be an Error object if the watchman service is not
// installed, or if any of the names listed in the `required`
// array are not supported by the server
console.log('watchman not installed');
console.error(error);
}
// resp will be an extended version response:
// {'version': '3.8.0', 'capabilities': {'relative_root': true}}
console.log(resp);
});
```

If watchman is not installed, what actually happens is an `Unhandled 'error' event` is thrown and cannot be caught. The only way to catch this is to add a `client.on('error', ...)` callback. This is doable but then further precaution needs to be taken to avoid catching other errors in that callback. It would be much more convenient if it worked as documented. I have a minimal reproduction example here: https://github.com/robrichard/watchman-error/blob/master/index.js

Contributor guide

Open the contributing guide

Research direction

Start with the minimal reproduction in index.js and compare its client.capabilityCheck behavior with the linked Watchman Node.js documentation. Trace how the fb-watchman client reports a missing Watchman service, then verify that the documented callback receives the error without an unhandled 'error' event.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.