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
This commit is contained in:
Igor Minar 2015-07-02 21:53:12 -07:00
parent 1c94c32f4d
commit a7ea2e5566
1 changed files with 14 additions and 9 deletions

View File

@ -51,6 +51,7 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin {
rebuild(treeDiff: DiffResult) { rebuild(treeDiff: DiffResult) {
let pathsToEmit = []; let pathsToEmit = [];
let pathsWithErrors = []; let pathsWithErrors = [];
let errorMessages = [];
treeDiff.addedPaths.concat(treeDiff.changedPaths) treeDiff.addedPaths.concat(treeDiff.changedPaths)
.forEach((tsFilePath) => { .forEach((tsFilePath) => {
@ -80,9 +81,10 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin {
let output = this.tsService.getEmitOutput(tsFilePath); let output = this.tsService.getEmitOutput(tsFilePath);
if (output.emitSkipped) { if (output.emitSkipped) {
let errorFound = this.logError(tsFilePath); let errorFound = this.collectErrors(tsFilePath);
if (errorFound) { if (errorFound) {
pathsWithErrors.push(tsFilePath); pathsWithErrors.push(tsFilePath);
errorMessages.push(errorFound);
} }
} else { } else {
output.outputFiles.forEach(o => { output.outputFiles.forEach(o => {
@ -95,7 +97,8 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin {
if (pathsWithErrors.length) { if (pathsWithErrors.length) {
this.previousRunFailed = true; 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; error['showStack'] = false;
throw error; throw error;
} else if (this.previousRunFailed) { } else if (this.previousRunFailed) {
@ -105,23 +108,25 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin {
} }
private logError(tsFilePath) { private collectErrors(tsFilePath): String {
let allDiagnostics = this.tsService.getCompilerOptionsDiagnostics() let allDiagnostics = this.tsService.getCompilerOptionsDiagnostics()
.concat(this.tsService.getSyntacticDiagnostics(tsFilePath)) .concat(this.tsService.getSyntacticDiagnostics(tsFilePath))
.concat(this.tsService.getSemanticDiagnostics(tsFilePath)); .concat(this.tsService.getSemanticDiagnostics(tsFilePath));
let errors = [];
allDiagnostics.forEach(diagnostic => { allDiagnostics.forEach(diagnostic => {
let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"); let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
if (diagnostic.file) { if (diagnostic.file) {
let{line, character} = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); let{line, character} = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
console.log(` Error ${diagnostic.file.fileName} (${line + 1},${character + 1}): ` + errors.push(` ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
`${message}`);
} else { } 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) { if (errorMessages.length) {
this.previousRunFailed = true; this.previousRunFailed = true;
console.log(errorMessages.join('\n')); var error =
var error = new Error('Typescript found errors listed above...'); new Error('Typescript found the following errors:\n' + errorMessages.join('\n'));
error['showStack'] = false; error['showStack'] = false;
throw error; throw error;
} else { } else {