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

@ -7,7 +7,7 @@
*/
export {DecoratorDownlevelCompilerHost, MetadataWriterHost} from './src/compiler_host';
export {CodegenExtension, main} from './src/main';
export {CodegenExtension, UserError, main} from './src/main';
export {default as AngularCompilerOptions} from './src/options';
export * from './src/cli_options';

View File

@ -16,6 +16,8 @@ import NgOptions from './options';
import {MetadataWriterHost, DecoratorDownlevelCompilerHost, TsickleCompilerHost} from './compiler_host';
import {CliOptions} from './cli_options';
export {UserError} from './tsc';
export type CodegenExtension =
(ngOptions: NgOptions, cliOptions: CliOptions, program: ts.Program, host: ts.CompilerHost) =>
Promise<void>;

View File

@ -24,6 +24,15 @@ export interface CompilerInterface {
emit(program: ts.Program): number;
}
export class UserError extends Error {
constructor(message: string) {
super(message);
this.message = message;
this.name = 'UserError';
this.stack = new Error().stack;
}
}
const DEBUG = false;
function debug(msg: string, ...o: any[]) {
@ -48,7 +57,7 @@ export function formatDiagnostics(diags: ts.Diagnostic[]): string {
export function check(diags: ts.Diagnostic[]) {
if (diags && diags.length && diags[0]) {
throw new Error(formatDiagnostics(diags));
throw new UserError(formatDiagnostics(diags));
}
}