Skip to content

Commit 4b177a1

Browse files
authored
Ensure readJson in build throws when errors are present (microsoft#55466)
1 parent 6d52028 commit 4b177a1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

scripts/build/utils.mjs

+8-2
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,18 @@ export class ExecError extends Error {
7272
}
7373

7474
/**
75-
* Reads JSON data with optional comments using the LKG TypeScript compiler
75+
* Reads JSON data with optional comments
7676
* @param {string} jsonPath
7777
*/
7878
export function readJson(jsonPath) {
7979
const jsonText = fs.readFileSync(jsonPath, "utf8");
80-
return JSONC.parse(jsonText);
80+
/** @type {JSONC.ParseError[]} */
81+
const errors = [];
82+
const result = JSONC.parse(jsonText, errors);
83+
if (errors.length) {
84+
throw new Error(`Error parsing ${jsonPath}`);
85+
}
86+
return result;
8187
}
8288

8389
/**

0 commit comments

Comments
 (0)