From bff9c344b6c5b30419e29168811895407fee33c2 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Mon, 14 Apr 2025 11:22:11 +0100 Subject: [PATCH] Log when attempting to load from nonexisting JSON file --- src/utils.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/utils.ts b/src/utils.ts index c8ab2916..0b0e3dcd 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -34,6 +34,13 @@ export type Json = JsonArray | JsonObject; * @param paths - An array of path segments which will be joined using the system's path delimiter. */ export function loadJsonFile(...paths: string[]): T { - const file = fs.readFileSync(path.join(...paths), { encoding: "utf-8" }); + const joinedPaths = path.join(...paths); + + if (!fs.existsSync(joinedPaths)) { + console.debug(`Skipping nonexisting file: ${joinedPaths}`); + return {} as T; + } + + const file = fs.readFileSync(joinedPaths, { encoding: "utf-8" }); return JSON.parse(file); }