Skip to content

Commit db73c0c

Browse files
RoopeHakulinenfilipesilva
authored andcommitted
feature(config): improved error message for invalid angular-cli.json (#2565)
Earlier invalid angular-cli.json yielded only "Error". Now it prints something like: Parsing angular-cli.json failed. Please make sure your angular-cli.json is valid JSON. Error: SyntaxError: Unexpected token s in JSON at position 2 Almost the same message is now also used for the other configuration files (schema and other).
1 parent 8bf69d9 commit db73c0c

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

packages/angular-cli/models/config/config.ts

+17-6
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import {SchemaClass, SchemaClassFactory} from '../json-schema/schema-class-facto
66

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

9-
10-
export class InvalidConfigError extends Error {
11-
constructor(err: Error) {
12-
super(err.message);
9+
class InvalidConfigError extends Error {
10+
constructor(message: string) {
11+
super(message);
12+
this.message = message;
13+
this.name = 'InvalidConfigError';
1314
}
1415
}
1516

@@ -61,7 +62,7 @@ export class CliConfig<JsonType> {
6162
try {
6263
schema = JSON.parse(schemaContent);
6364
} catch (err) {
64-
throw new InvalidConfigError(err);
65+
throw new InvalidConfigError(err.message);
6566
}
6667

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

8182
try {
8283
content = JSON.parse(configContent);
84+
} catch (err) {
85+
throw new InvalidConfigError(
86+
'Parsing angular-cli.json failed. Please make sure your angular-cli.json'
87+
+ ' is valid JSON. Error:\n' + err
88+
);
89+
}
90+
91+
try {
8392
schema = JSON.parse(schemaContent);
8493
others = otherContents.map(otherContent => JSON.parse(otherContent));
8594
} catch (err) {
86-
throw new InvalidConfigError(err);
95+
throw new InvalidConfigError(
96+
`Parsing Angular CLI schema or other configuration files failed. Error:\n${err}`
97+
);
8798
}
8899

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

0 commit comments

Comments
 (0)