refactor(compiler): change ngc error handling

Do not print stack trace for user errors
Print stack trace for compiler internal errors
This commit is contained in:
Bowen Ni
2016-11-30 13:59:53 -08:00
committed by Alex Rickabaugh
parent 75d1617b63
commit 9761db5ac2
6 changed files with 152 additions and 10 deletions

View File

@ -22,14 +22,24 @@ function codegen(
return CodeGenerator.create(ngOptions, cliOptions, program, host).codegen();
}
export function main(args: any, consoleError: any): Promise<number> {
const project = args.p || args.project || '.';
const cliOptions = new tsc.NgcCliOptions(args);
return tsc.main(project, cliOptions, codegen).then(() => 0).catch(e => {
if (e instanceof tsc.UserError) {
consoleError(e.message);
return Promise.resolve(0);
} else {
consoleError(e.stack);
consoleError('Compilation failed');
return Promise.resolve(1);
}
});
}
// CLI entry point
if (require.main === module) {
const args = require('minimist')(process.argv.slice(2));
const project = args.p || args.project || '.';
const cliOptions = new tsc.NgcCliOptions(args);
tsc.main(project, cliOptions, codegen).then(exitCode => process.exit(exitCode)).catch(e => {
console.error(e.stack);
console.error('Compilation failed');
process.exit(1);
});
}
main(args, console.error).then((exitCode: number) => process.exit(exitCode));
}