Skip to content

Commit

Permalink
fix bug (#314)
Browse files Browse the repository at this point in the history
Co-authored-by: Katie Dai <kdai7@ibm.com>
  • Loading branch information
kdai7 and Katie Dai committed Jan 31, 2023
1 parent cc64dde commit f781405
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/Watchman.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module.exports = class Watchman {
this._requestStream = undefined;
this._jsonStream = undefined;
this._errors = 0;
this._error = false;
this._watching = false;
}

Expand All @@ -78,6 +79,7 @@ module.exports = class Watchman {

_watchError() {
this._errors++;
this._error = true;
this.end(this._rewatchOnTimeout);
delay(this._errors * 1000).then(() => {
if (this._rewatchOnTimeout)
Expand All @@ -102,7 +104,7 @@ module.exports = class Watchman {
this._logger.debug('Watchman: watch started');
this._watchStart = Date.now();
this._watching = true;
this._errors = 0;
this._error = false;
}
})
.on('error', (err) => {
Expand All @@ -113,6 +115,9 @@ module.exports = class Watchman {
})
.on('close', () => {
this._watching = false;
if (!this._error) {
this._errors = 0;
}
if (this._logger) {
this._logger.info(`GET ${this._requestOptions.uri} closed. rewatchOnTimeout: ${this._rewatchOnTimeout}, errors: ${this._errors}`);
}
Expand All @@ -124,18 +129,18 @@ module.exports = class Watchman {
parser.on('data', (data) => {
if (data.type === 'ERROR') {
if (this._logger) {
this._logger.error(`GET ${this._requestOptions.uri} errored at data.type === ERROR`, JSON.stringify(data.object));
this._logger.error(`GET ${this._requestOptions.uri} errored at data.type === ERROR, aborting`, JSON.stringify(data.object));
}
this._watchError();
this._requestStream.abort();
} else {
this.objectHandler(data);
}
});
parser.on('error', (err) => {
if (this._logger) {
this._logger.error(`GET ${this._requestOptions.uri} errored at parser.on error`, err);
this._logger.error(`GET ${this._requestOptions.uri} errored at parser.on error, aborting`, err);
}
this._watchError();
this._requestStream.abort();
});
this._jsonStream = this._requestStream.pipe(parser);
}
Expand Down

0 comments on commit f781405

Please sign in to comment.