| 419 | } |
| 420 | |
| 421 | private onWatchFsAdd(msg: WatchFsAddMessage): void { |
| 422 | if (this.fsWatchHandler === undefined) { |
| 423 | this.send( |
| 424 | buildAck(msg.id, ErrorCode.INTERNAL_ERROR, 'fs watch handler not wired', {}), |
| 425 | ); |
| 426 | return; |
| 427 | } |
| 428 | const { session_id, paths } = msg.payload; |
| 429 | const handler = this.fsWatchHandler; |
| 430 | void handler |
| 431 | .add(session_id, this.id, paths) |
| 432 | .then((result) => { |
| 433 | if (!result.ok) { |
| 434 | this.send(buildAck(msg.id, result.code, result.msg, {})); |
| 435 | return; |
| 436 | } |
| 437 | this.send( |
| 438 | buildAck(msg.id, 0, 'success', { |
| 439 | watched_paths: result.watched_paths, |
| 440 | current_count: result.current_count, |
| 441 | }), |
| 442 | ); |
| 443 | }) |
| 444 | .catch((err: unknown) => { |
| 445 | this.logger.warn({ err: String(err) }, 'watch_fs_add handler threw'); |
| 446 | this.send( |
| 447 | buildAck(msg.id, ErrorCode.INTERNAL_ERROR, 'watch_fs_add failed', {}), |
| 448 | ); |
| 449 | }); |
| 450 | } |
| 451 | |
| 452 | private onWatchFsRemove(msg: WatchFsRemoveMessage): void { |
| 453 | if (this.fsWatchHandler === undefined) { |