Skip to content

Commit b7b2c33

Browse files
authored
Handle if reading tsconfig file fails (#37563)
Fixes #36862
1 parent a1c8608 commit b7b2c33

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/server/editorServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1974,7 +1974,7 @@ namespace ts.server {
19741974
// Read updated contents from disk
19751975
const configFilename = normalizePath(project.getConfigFilePath());
19761976

1977-
const configFileContent = this.host.readFile(configFilename)!; // TODO: GH#18217
1977+
const configFileContent = this.host.readFile(configFilename) || "";
19781978

19791979
const result = parseJsonText(configFilename, configFileContent);
19801980
if (!result.endOfFileToken) {

src/testRunner/unittests/tsserver/configuredProjects.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,4 +1233,27 @@ declare var console: {
12331233
checkWatchedDirectories(host, watchedRecursiveDirectories, /*recursive*/ true);
12341234
});
12351235
});
1236+
1237+
describe("unittests:: tsserver:: ConfiguredProjects:: when reading tsconfig file fails", () => {
1238+
it("should be tolerated without crashing the server", () => {
1239+
const configFile = {
1240+
path: `${tscWatch.projectRoot}/tsconfig.json`,
1241+
content: ""
1242+
};
1243+
const file1 = {
1244+
path: `${tscWatch.projectRoot}/file1.ts`,
1245+
content: "let t = 10;"
1246+
};
1247+
1248+
const host = createServerHost([file1, configFile]);
1249+
const projectService = createProjectService(host);
1250+
const originalReadFile = host.readFile;
1251+
host.readFile = f => {
1252+
return f === configFile.path ?
1253+
undefined :
1254+
originalReadFile.call(host, f);
1255+
};
1256+
projectService.openClientFile(file1.path);
1257+
});
1258+
});
12361259
}

0 commit comments

Comments
 (0)