From a696f4aade95f0da795594bcfca15ff2472497df Mon Sep 17 00:00:00 2001 From: Bowen Ni Date: Mon, 6 Feb 2017 15:26:30 -0800 Subject: [PATCH] fix(compiler): improve error messages in aot compiler (#14333) Do not print the stack trace when the component is not declared in the module. PR Close #14333 --- modules/@angular/compiler/src/aot/compiler.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/@angular/compiler/src/aot/compiler.ts b/modules/@angular/compiler/src/aot/compiler.ts index 3446036e61..8da7da80a4 100644 --- a/modules/@angular/compiler/src/aot/compiler.ts +++ b/modules/@angular/compiler/src/aot/compiler.ts @@ -19,6 +19,7 @@ import * as o from '../output/output_ast'; import {CompiledStylesheet, StyleCompiler} from '../style_compiler'; import {SummaryResolver} from '../summary_resolver'; import {TemplateParser} from '../template_parser/template_parser'; +import {syntaxError} from '../util'; import {ViewCompiler} from '../view_compiler/view_compiler'; import {AotCompilerHost} from './compiler_host'; @@ -290,8 +291,9 @@ export function analyzeAndValidateNgModules( const result = analyzeNgModules(programStaticSymbols, host, metadataResolver); if (result.symbolsMissingModule && result.symbolsMissingModule.length) { const messages = result.symbolsMissingModule.map( - s => `Cannot determine the module for class ${s.name} in ${s.filePath}!`); - throw new Error(messages.join('\n')); + s => + `Cannot determine the module for class ${s.name} in ${s.filePath}! Add ${s.name} to the NgModule to fix it.`); + throw syntaxError(messages.join('\n')); } return result; }