Skip to content

Commit 3db588f

Browse files
alan-agius4filipesilva
authored andcommitted
refactor(@schematics/angular): throw on AST parse errors
1 parent 8fb5259 commit 3db588f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/schematics/angular/utility/json-file.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import { JsonValue } from '@angular-devkit/core';
1010
import { Tree } from '@angular-devkit/schematics';
11-
import { Node, applyEdits, findNodeAtLocation, getNodeValue, modify, parseTree } from 'jsonc-parser';
11+
import { Node, ParseError, applyEdits, findNodeAtLocation, getNodeValue, modify, parseTree, printParseErrorCode } from 'jsonc-parser';
1212

1313
export type InsertionIndex = (properties: string[]) => number;
1414
export type JSONPath = (string | number)[];
@@ -35,7 +35,12 @@ export class JSONFile {
3535
return this._jsonAst;
3636
}
3737

38-
this._jsonAst = parseTree(this.content);
38+
const errors: ParseError[] = [];
39+
this._jsonAst = parseTree(this.content, errors);
40+
if (errors.length) {
41+
const { error, offset } = errors[0];
42+
throw new Error(`Failed to parse "${this.path}" as JSON AST Object. ${printParseErrorCode(error)} at location: ${offset}.`);
43+
}
3944

4045
return this._jsonAst;
4146
}

0 commit comments

Comments
 (0)