Skip to content

Commit 53da062

Browse files
alan-agius4alexeagle
authored andcommitted
fix(@angular-devkit/schematics): throw InvalidCollectionJsonException when collection file is invalid
Closes #11818
1 parent 713b503 commit 53da062

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

+14-2
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,
@@ -48,8 +50,18 @@ export class CollectionCannotBeResolvedException extends BaseException {
4850
}
4951
}
5052
export class InvalidCollectionJsonException extends BaseException {
51-
constructor(_name: string, path: string) {
52-
super(`Collection JSON at path ${JSON.stringify(path)} is invalid.`);
53+
constructor(
54+
_name: string,
55+
path: string,
56+
jsonException?: UnexpectedEndOfInputException | InvalidJsonCharacterException,
57+
) {
58+
let msg = `Collection JSON at path ${JSON.stringify(path)} is invalid.`;
59+
60+
if (jsonException) {
61+
msg = `${msg} ${jsonException.message}`;
62+
}
63+
64+
super(msg);
5365
}
5466
}
5567
export class SchematicMissingFactoryException extends BaseException {

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

+13-2
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)