Skip to content

feature(config): improved error message for invalid angular-cli.json #2565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions packages/angular-cli/models/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import {SchemaClass, SchemaClassFactory} from '../json-schema/schema-class-facto

const DEFAULT_CONFIG_SCHEMA_PATH = path.join(__dirname, '../../lib/config/schema.json');


export class InvalidConfigError extends Error {
constructor(err: Error) {
super(err.message);
class InvalidConfigError extends Error {
constructor(message: string) {
super(message);
this.message = message;
this.name = 'InvalidConfigError';
}
}

Expand Down Expand Up @@ -61,7 +62,7 @@ export class CliConfig<JsonType> {
try {
schema = JSON.parse(schemaContent);
} catch (err) {
throw new InvalidConfigError(err);
throw new InvalidConfigError(err.message);
}

return new CliConfig<ConfigType>(null, schema, content, global);
Expand All @@ -80,10 +81,20 @@ export class CliConfig<JsonType> {

try {
content = JSON.parse(configContent);
} catch (err) {
throw new InvalidConfigError(
'Parsing angular-cli.json failed. Please make sure your angular-cli.json'
+ ' is valid JSON. Error:\n' + err
);
}

try {
schema = JSON.parse(schemaContent);
others = otherContents.map(otherContent => JSON.parse(otherContent));
} catch (err) {
throw new InvalidConfigError(err);
throw new InvalidConfigError(
`Parsing Angular CLI schema or other configuration files failed. Error:\n${err}`
);
}

return new CliConfig<T>(configPath, schema, content, others);
Expand Down