Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3927f93

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

File tree

1 file changed

+19
-10
lines changed
  • packages/@angular/cli/models/config

1 file changed

+19
-10
lines changed

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

Lines changed: 19 additions & 10 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /