Skip to content

Commit 10ec556

Browse files
Charles LydingBrocco
Charles Lyding
authored andcommitted
fix(@angular/cli): provide file path with config parse errors
1 parent ebb56d7 commit 10ec556

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

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

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
33
import * as ts from 'typescript';
4+
import { stripIndent } from 'common-tags';
45

56
import {SchemaClass, SchemaClassFactory} from '@ngtools/json-schema';
67

@@ -73,15 +74,13 @@ export class CliConfig<JsonType> {
7374
}
7475

7576
static fromConfigPath<T>(configPath: string, otherPath: string[] = []): CliConfig<T> {
76-
const configContent = fs.existsSync(configPath)
77-
? ts.sys.readFile(configPath)
78-
: '{}';
77+
const configContent = ts.sys.readFile(configPath) || '{}';
7978
const schemaContent = fs.readFileSync(DEFAULT_CONFIG_SCHEMA_PATH, 'utf-8');
8079

8180
let otherContents = new Array<string>();
8281
if (configPath !== otherPath[0]) {
8382
otherContents = otherPath
84-
.map(path => fs.existsSync(path) && ts.sys.readFile(path))
83+
.map(path => ts.sys.readFile(path))
8584
.filter(content => !!content);
8685
}
8786

@@ -92,18 +91,28 @@ export class CliConfig<JsonType> {
9291
try {
9392
content = JSON.parse(configContent);
9493
} catch (err) {
95-
throw new InvalidConfigError(
96-
'Parsing .angular-cli.json failed. Please make sure your .angular-cli.json'
97-
+ ' is valid JSON. Error:\n' + err
98-
);
94+
throw new InvalidConfigError(stripIndent`
95+
Parsing '${configPath}' failed. Ensure the file is valid JSON.
96+
Error: ${err.message}
97+
`);
9998
}
10099

100+
others = otherContents.map(otherContent => {
101+
try {
102+
return JSON.parse(otherContent);
103+
} catch (err) {
104+
throw new InvalidConfigError(stripIndent`
105+
Parsing '${configPath}' failed. Ensure the file is valid JSON.
106+
Error: ${err.message}
107+
`);
108+
}
109+
});
110+
101111
try {
102112
schema = JSON.parse(schemaContent);
103-
others = otherContents.map(otherContent => JSON.parse(otherContent));
104113
} catch (err) {
105114
throw new InvalidConfigError(
106-
`Parsing Angular CLI schema or other configuration files failed. Error:\n${err}`
115+
`Parsing Angular CLI schema failed. Error:\n${err.message}`
107116
);
108117
}
109118

0 commit comments

Comments
 (0)