From 398fa0a578a12a1a07ebacc6bd3b40b7b6143368 Mon Sep 17 00:00:00 2001 From: sammamama Date: Sun, 2 Feb 2025 16:43:36 +1100 Subject: [PATCH] error handling: fix error handling when global_config.json is in incorrect format Fixes #1404. I added a dialog box error function, that gets thrown whenever json format is found to be incorrect. --- app/common/enterprise-util.ts | 4 ++++ app/common/messages.ts | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/app/common/enterprise-util.ts b/app/common/enterprise-util.ts index 3724e0381..87fff3eff 100644 --- a/app/common/enterprise-util.ts +++ b/app/common/enterprise-util.ts @@ -1,3 +1,4 @@ +import {dialog} from "electron/main"; import fs from "node:fs"; import path from "node:path"; import process from "node:process"; @@ -6,6 +7,7 @@ import {z} from "zod"; import {enterpriseConfigSchemata} from "./config-schemata.js"; import Logger from "./logger-util.js"; +import * as Messages from "./messages.js"; type EnterpriseConfig = { [Key in keyof typeof enterpriseConfigSchemata]: z.output< @@ -40,6 +42,8 @@ function reloadDatabase(): void { .partial() .parse(data); } catch (error: unknown) { + const {title, content} = Messages.enterpriseInvalidJson(enterpriseFile); + dialog.showErrorBox(title, content); logger.log("Error while JSON parsing global_config.json: "); logger.log(error); } diff --git a/app/common/messages.ts b/app/common/messages.ts index 545b0991d..3c29b6e95 100644 --- a/app/common/messages.ts +++ b/app/common/messages.ts @@ -36,3 +36,12 @@ export function orgRemovalError(url: string): DialogBoxError { content: "Please contact your system administrator.", }; } + +export function enterpriseInvalidJson( + pathToConfigFile: string, +): DialogBoxError { + return { + title: "Invalid JSON", + content: `Correct the invalid JSON format in global_config.json.\nIt can be found in:\n${pathToConfigFile}`, + }; +}