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:

committed by
Alex Rickabaugh

parent
75d1617b63
commit
9761db5ac2
@ -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';
|
||||
|
@ -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>;
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user