Skip to content

fix(@angular-devkit/schematics): throw `InvalidCollectionJsonExceptio… #11841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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