From 4b177a186a03636be9cf8b6f6b024452f2aed1cc Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 6 Sep 2023 11:19:33 -0700 Subject: [PATCH] Ensure readJson in build throws when errors are present (#55466) --- scripts/build/utils.mjs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/build/utils.mjs b/scripts/build/utils.mjs index f36d2ee9c01..a0d319f6397 100644 --- a/scripts/build/utils.mjs +++ b/scripts/build/utils.mjs @@ -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; } /**