mirror of
https://github.com/element-hq/element-desktop
synced 2025-04-21 09:03:56 +02:00
Log when attempting to load from nonexisting JSON file
This commit is contained in:
parent
30a464fcdc
commit
bff9c344b6
@ -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.
|
* @param paths - An array of path segments which will be joined using the system's path delimiter.
|
||||||
*/
|
*/
|
||||||
export function loadJsonFile<T extends Json>(...paths: string[]): T {
|
export function loadJsonFile<T extends Json>(...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);
|
return JSON.parse(file);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user