From 5c44a0ff3e93628a4cf59509c103dc827504d317 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Wed, 22 Apr 2015 15:58:04 -0700 Subject: [PATCH] Improve error message when encountering an invalid tsconfig.json file. --- src/compiler/commandLineParser.ts | 2 +- src/compiler/diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++++ src/compiler/tsc.ts | 9 ++++++--- src/services/shims.ts | 2 +- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 3645695ca76..a83e742a122 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -299,7 +299,7 @@ module ts { * @param basePath A root directory to resolve relative path entries in the config * file to. e.g. outDir */ - export function parseConfigFile(json: any, host: ParseConfigHost, basePath?: string): ParsedCommandLine { + export function parseConfigFile(json: any, host: ParseConfigHost, basePath: string): ParsedCommandLine { var errors: Diagnostic[] = []; return { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 90f0ed0a0df..df7928d5717 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -439,6 +439,7 @@ module ts { 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." }, Cannot_read_file_0_Colon_1: { code: 5012, category: DiagnosticCategory.Error, key: "Cannot read file '{0}': {1}" }, Unsupported_file_encoding: { code: 5013, category: DiagnosticCategory.Error, key: "Unsupported file encoding." }, + Failed_to_parse_file_0_Colon_1: { code: 5014, category: DiagnosticCategory.Error, key: "Failed to parse file '{0}': {1}." }, Unknown_compiler_option_0: { code: 5023, category: DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." }, Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: DiagnosticCategory.Error, key: "Compiler option '{0}' requires a value of type {1}." }, Could_not_write_file_0_Colon_1: { code: 5033, category: DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 48ef245c766..afd21593f81 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1744,6 +1744,10 @@ "category": "Error", "code": 5013 }, + "Failed to parse file '{0}': {1}.": { + "category": "Error", + "code": 5014 + }, "Unknown compiler option '{0}'.": { "category": "Error", "code": 5023 diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 7eb86efbfae..89464e6b6e4 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -208,9 +208,12 @@ module ts { if (!cachedProgram) { if (configFileName) { - var configObject = readConfigFile(configFileName); - if (!configObject) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.Unable_to_open_file_0, configFileName)); + try { + var configObject = readConfigFile(configFileName); + } + catch (e) + { + reportDiagnostic(createCompilerDiagnostic(Diagnostics.Failed_to_parse_file_0_Colon_1, configFileName, e.message)); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } var configParseResult = parseConfigFile(configObject, sys, getDirectoryPath(configFileName)); diff --git a/src/services/shims.ts b/src/services/shims.ts index 99df0e093a4..6caec3cd23f 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -811,7 +811,7 @@ module ts { return { options: {}, files: [], - errors: realizeDiagnostic(createCompilerDiagnostic(Diagnostics.Unable_to_open_file_0, fileName), '\r\n') + errors: realizeDiagnostic(createCompilerDiagnostic(Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message), '\r\n') } }