From a7ea2e5566d8df42428619dc635cb9cd92aa7810 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Thu, 2 Jul 2015 21:53:12 -0700 Subject: [PATCH] build(broccoli): concat all typescript error messages into the message of thrown exception This allows us to to do better error handling and for cli this means that we can show typescript errors in the output of the webserver --- tools/broccoli/broccoli-typescript.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tools/broccoli/broccoli-typescript.ts b/tools/broccoli/broccoli-typescript.ts index 7886da8e07..86180fa49c 100644 --- a/tools/broccoli/broccoli-typescript.ts +++ b/tools/broccoli/broccoli-typescript.ts @@ -51,6 +51,7 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin { rebuild(treeDiff: DiffResult) { let pathsToEmit = []; let pathsWithErrors = []; + let errorMessages = []; treeDiff.addedPaths.concat(treeDiff.changedPaths) .forEach((tsFilePath) => { @@ -80,9 +81,10 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin { let output = this.tsService.getEmitOutput(tsFilePath); if (output.emitSkipped) { - let errorFound = this.logError(tsFilePath); + let errorFound = this.collectErrors(tsFilePath); if (errorFound) { pathsWithErrors.push(tsFilePath); + errorMessages.push(errorFound); } } else { output.outputFiles.forEach(o => { @@ -95,7 +97,8 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin { if (pathsWithErrors.length) { this.previousRunFailed = true; - var error = new Error('Typescript found errors listed above...'); + var error = + new Error('Typescript found the following errors:\n' + errorMessages.join('\n')); error['showStack'] = false; throw error; } else if (this.previousRunFailed) { @@ -105,23 +108,25 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin { } - private logError(tsFilePath) { + private collectErrors(tsFilePath): String { let allDiagnostics = this.tsService.getCompilerOptionsDiagnostics() .concat(this.tsService.getSyntacticDiagnostics(tsFilePath)) .concat(this.tsService.getSemanticDiagnostics(tsFilePath)); + let errors = []; allDiagnostics.forEach(diagnostic => { let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"); if (diagnostic.file) { let{line, character} = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); - console.log(` Error ${diagnostic.file.fileName} (${line + 1},${character + 1}): ` + - `${message}`); + errors.push(` ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`); } else { - console.log(` Error: ${message}`); + errors.push(` Error: ${message}`); } }); - return !!allDiagnostics.length; + if (errors.length) { + return errors.join('\n'); + } } @@ -148,8 +153,8 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin { if (errorMessages.length) { this.previousRunFailed = true; - console.log(errorMessages.join('\n')); - var error = new Error('Typescript found errors listed above...'); + var error = + new Error('Typescript found the following errors:\n' + errorMessages.join('\n')); error['showStack'] = false; throw error; } else {