Skip to content

Commit

Permalink
fix(@angular-devkit/schematics): throw `InvalidCollectionJsonExceptio…
Browse files Browse the repository at this point in the history
…n` when collection file is invalid

Closes #11818
  • Loading branch information
alan-agius4 authored and alexeagle committed Sep 6, 2018
1 parent 5007a19 commit 54f7ea2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/
import {
BaseException,
InvalidJsonCharacterException,
JsonObject,
UnexpectedEndOfInputException,
isObservable,
normalize,
virtualFs,
Expand Down Expand Up @@ -52,8 +54,18 @@ export class CollectionCannotBeResolvedException extends BaseException {
}
}
export class InvalidCollectionJsonException extends BaseException {
constructor(_name: string, path: string) {
super(`Collection JSON at path ${JSON.stringify(path)} is invalid.`);
constructor(
_name: string,
path: string,
jsonException?: UnexpectedEndOfInputException | InvalidJsonCharacterException,
) {
let msg = `Collection JSON at path ${JSON.stringify(path)} is invalid.`;

if (jsonException) {
msg = `${msg} ${jsonException.message}`;
}

super(msg);
}
}
export class SchematicMissingFactoryException extends BaseException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { BaseException } from '@angular-devkit/core';
import {
BaseException,
InvalidJsonCharacterException,
UnexpectedEndOfInputException,
} from '@angular-devkit/core';
import * as core from '@angular-devkit/core/node';
import { dirname, join, resolve as resolvePath } from 'path';
import { RuleFactory } from '../src';
Expand All @@ -18,6 +22,7 @@ import {
CollectionCannotBeResolvedException,
CollectionMissingSchematicsMapException,
FileSystemEngineHostBase,
InvalidCollectionJsonException,
SchematicMissingFieldsException,
} from './file-system-engine-host-base';
import { readJsonFile } from './file-system-utility';
Expand Down Expand Up @@ -77,7 +82,7 @@ export class NodeModulesEngineHost extends FileSystemEngineHostBase {
if (name.replace(/\\/, '/').split('/').length > (name[0] == '@' ? 2 : 1)) {
try {
collectionPath = this._resolvePath(name, process.cwd());
} catch (_) {
} catch {
}
}

Expand All @@ -102,7 +107,13 @@ export class NodeModulesEngineHost extends FileSystemEngineHostBase {
return collectionPath;
}
} catch (e) {
if (
e instanceof InvalidJsonCharacterException || e instanceof UnexpectedEndOfInputException
) {
throw new InvalidCollectionJsonException(name, collectionPath, e);
}
}

throw new CollectionCannotBeResolvedException(name);
}

Expand Down

0 comments on commit 54f7ea2

Please sign in to comment.