Skip to content

Commit b1472d9

Browse files
author
Paul van Brenk
committed
Add error handling.
1 parent c6a9c8f commit b1472d9

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

src/services/shims.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -802,17 +802,27 @@ module ts {
802802
return this.forwardJSONCall(
803803
"getTSConfigFileInfo('" + fileName + "')",
804804
() => {
805-
var text = sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength());
806-
var json = /\S/.test(text) ? JSON.parse(text) : {};
807-
808-
var configFile = parseConfigFile(json, this.host, getDirectoryPath(normalizeSlashes(fileName)));
809-
810-
var realErrors = realizeDiagnostics(configFile.errors, '\r\n');
805+
let text = sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength());
806+
807+
try {
808+
var json = /\S/.test(text) ? JSON.parse(text) : {};
809+
}
810+
catch (e) {
811+
return {
812+
options: {},
813+
files: [],
814+
errors: realizeDiagnostic(createCompilerDiagnostic(Diagnostics.Unable_to_open_file_0, fileName), '\r\n')
815+
}
816+
}
817+
818+
if (json) {
819+
var configFile = parseConfigFile(json, this.host, getDirectoryPath(normalizeSlashes(fileName)));
820+
}
811821

812822
return {
813823
options: configFile.options,
814824
files: configFile.fileNames,
815-
errors: realErrors
825+
errors: realizeDiagnostics(configFile.errors, '\r\n')
816826
};
817827
});
818828
}

0 commit comments

Comments
 (0)