Ensure readJson in build throws when errors are present (#55466)

This commit is contained in:
Jake Bailey
2023-09-06 11:19:33 -07:00
committed by GitHub
parent 6d52028287
commit 4b177a186a

View File

@@ -72,12 +72,18 @@ export class ExecError extends Error {
}
/**
* Reads JSON data with optional comments using the LKG TypeScript compiler
* Reads JSON data with optional comments
* @param {string} jsonPath
*/
export function readJson(jsonPath) {
const jsonText = fs.readFileSync(jsonPath, "utf8");
return JSONC.parse(jsonText);
/** @type {JSONC.ParseError[]} */
const errors = [];
const result = JSONC.parse(jsonText, errors);
if (errors.length) {
throw new Error(`Error parsing ${jsonPath}`);
}
return result;
}
/**