Skip to content

Commit 5c44a0f

Browse files
author
Paul van Brenk
committed
Improve error message when encountering an invalid tsconfig.json file.
1 parent b1472d9 commit 5c44a0f

5 files changed

Lines changed: 13 additions & 5 deletions

File tree

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ module ts {
299299
* @param basePath A root directory to resolve relative path entries in the config
300300
* file to. e.g. outDir
301301
*/
302-
export function parseConfigFile(json: any, host: ParseConfigHost, basePath?: string): ParsedCommandLine {
302+
export function parseConfigFile(json: any, host: ParseConfigHost, basePath: string): ParsedCommandLine {
303303
var errors: Diagnostic[] = [];
304304

305305
return {

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ module ts {
439439
Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: DiagnosticCategory.Error, key: "Cannot find the common subdirectory path for the input files." },
440440
Cannot_read_file_0_Colon_1: { code: 5012, category: DiagnosticCategory.Error, key: "Cannot read file '{0}': {1}" },
441441
Unsupported_file_encoding: { code: 5013, category: DiagnosticCategory.Error, key: "Unsupported file encoding." },
442+
Failed_to_parse_file_0_Colon_1: { code: 5014, category: DiagnosticCategory.Error, key: "Failed to parse file '{0}': {1}." },
442443
Unknown_compiler_option_0: { code: 5023, category: DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." },
443444
Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: DiagnosticCategory.Error, key: "Compiler option '{0}' requires a value of type {1}." },
444445
Could_not_write_file_0_Colon_1: { code: 5033, category: DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" },

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,10 @@
17441744
"category": "Error",
17451745
"code": 5013
17461746
},
1747+
"Failed to parse file '{0}': {1}.": {
1748+
"category": "Error",
1749+
"code": 5014
1750+
},
17471751
"Unknown compiler option '{0}'.": {
17481752
"category": "Error",
17491753
"code": 5023

src/compiler/tsc.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,12 @@ module ts {
208208

209209
if (!cachedProgram) {
210210
if (configFileName) {
211-
var configObject = readConfigFile(configFileName);
212-
if (!configObject) {
213-
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Unable_to_open_file_0, configFileName));
211+
try {
212+
var configObject = readConfigFile(configFileName);
213+
}
214+
catch (e)
215+
{
216+
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Failed_to_parse_file_0_Colon_1, configFileName, e.message));
214217
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
215218
}
216219
var configParseResult = parseConfigFile(configObject, sys, getDirectoryPath(configFileName));

src/services/shims.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ module ts {
811811
return {
812812
options: {},
813813
files: [],
814-
errors: realizeDiagnostic(createCompilerDiagnostic(Diagnostics.Unable_to_open_file_0, fileName), '\r\n')
814+
errors: realizeDiagnostic(createCompilerDiagnostic(Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message), '\r\n')
815815
}
816816
}
817817

0 commit comments

Comments
 (0)