Skip to content

Commit 54f7ea2

Browse files
alan-agius4alexeagle
authored andcommittedSep 6, 2018
fix(@angular-devkit/schematics): throw InvalidCollectionJsonException when collection file is invalid
Closes #11818
1 parent 5007a19 commit 54f7ea2

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed
 

‎packages/angular_devkit/schematics/tools/file-system-engine-host-base.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
*/
88
import {
99
BaseException,
10+
InvalidJsonCharacterException,
1011
JsonObject,
12+
UnexpectedEndOfInputException,
1113
isObservable,
1214
normalize,
1315
virtualFs,
@@ -52,8 +54,18 @@ export class CollectionCannotBeResolvedException extends BaseException {
5254
}
5355
}
5456
export class InvalidCollectionJsonException extends BaseException {
55-
constructor(_name: string, path: string) {
56-
super(`Collection JSON at path ${JSON.stringify(path)} is invalid.`);
57+
constructor(
58+
_name: string,
59+
path: string,
60+
jsonException?: UnexpectedEndOfInputException | InvalidJsonCharacterException,
61+
) {
62+
let msg = `Collection JSON at path ${JSON.stringify(path)} is invalid.`;
63+
64+
if (jsonException) {
65+
msg = `${msg} ${jsonException.message}`;
66+
}
67+
68+
super(msg);
5769
}
5870
}
5971
export class SchematicMissingFactoryException extends BaseException {

‎packages/angular_devkit/schematics/tools/node-module-engine-host.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { BaseException } from '@angular-devkit/core';
8+
import {
9+
BaseException,
10+
InvalidJsonCharacterException,
11+
UnexpectedEndOfInputException,
12+
} from '@angular-devkit/core';
913
import * as core from '@angular-devkit/core/node';
1014
import { dirname, join, resolve as resolvePath } from 'path';
1115
import { RuleFactory } from '../src';
@@ -18,6 +22,7 @@ import {
1822
CollectionCannotBeResolvedException,
1923
CollectionMissingSchematicsMapException,
2024
FileSystemEngineHostBase,
25+
InvalidCollectionJsonException,
2126
SchematicMissingFieldsException,
2227
} from './file-system-engine-host-base';
2328
import { readJsonFile } from './file-system-utility';
@@ -77,7 +82,7 @@ export class NodeModulesEngineHost extends FileSystemEngineHostBase {
7782
if (name.replace(/\\/, '/').split('/').length > (name[0] == '@' ? 2 : 1)) {
7883
try {
7984
collectionPath = this._resolvePath(name, process.cwd());
80-
} catch (_) {
85+
} catch {
8186
}
8287
}
8388

@@ -102,7 +107,13 @@ export class NodeModulesEngineHost extends FileSystemEngineHostBase {
102107
return collectionPath;
103108
}
104109
} catch (e) {
110+
if (
111+
e instanceof InvalidJsonCharacterException || e instanceof UnexpectedEndOfInputException
112+
) {
113+
throw new InvalidCollectionJsonException(name, collectionPath, e);
114+
}
105115
}
116+
106117
throw new CollectionCannotBeResolvedException(name);
107118
}
108119

0 commit comments

Comments
 (0)
Please sign in to comment.