Handle invalid visual baseline JSON

This commit is contained in:
thePR0M3TH3AN committed 2025-10-12 14:12:31 -04:00
1 parent 67ab96686f
commit 25cda54a7a
1 file changed
+10 -3
+10 -3
View File
@@ -17,9 +17,16 @@ type BaselineMap = Record<string, string>;
const BASELINE_FILE_PATH = resolve(__dirname, "baselines.json");
let dirty = false;
const baselines: BaselineMap = JSON.parse(
readFileSync(BASELINE_FILE_PATH, "utf-8")
);
let baselines: BaselineMap;
const baselineFileContents = readFileSync(BASELINE_FILE_PATH, "utf-8");
try {
baselines = JSON.parse(baselineFileContents);
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
throw new Error(`Invalid JSON in ${BASELINE_FILE_PATH}: ${message}`);
}
export function getBaseline(key: BaselineKey): Buffer {
const base64 = baselines[key];