Skip to content

Commit 52d7c72

Browse files
committed
Add comment about swallowing exception
1 parent e30a66d commit 52d7c72

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/server/server.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,11 +753,13 @@ namespace ts.server {
753753
const sys = <ServerHost>ts.sys;
754754
// use watchGuard process on Windows when node version is 4 or later
755755
const useWatchGuard = process.platform === "win32" && getNodeMajorVersion() >= 4;
756-
const originalWatchDirectory = sys.watchDirectory;
756+
const originalWatchDirectory: ServerHost["watchDirectory"] = sys.watchDirectory.bind(sys);
757757
const noopWatcher: FileWatcher = { close: noop };
758+
// This is the function that catches the exceptions when watching directory, and yet lets project service continue to function
759+
// Eg. on linux the number of watches are limited and one could easily exhaust watches and the exception ENOSPC is thrown when creating watcher at that point
758760
function watchDirectorySwallowingException(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher {
759761
try {
760-
return originalWatchDirectory.call(sys, path, callback, recursive);
762+
return originalWatchDirectory(path, callback, recursive);
761763
}
762764
catch (e) {
763765
logger.info(`Exception when creating directory watcher: ${e.message}`);

0 commit comments

Comments
 (0)