Skip to content

Commit

Permalink
error handling: fix error handling when global_config.json is in inco…
Browse files Browse the repository at this point in the history
…rrect format

Fixes #1404. I added a dialog box error function, that gets thrown whenever json format is found to be incorrect.
  • Loading branch information
sammamama committed Feb 6, 2025
1 parent 13f3818 commit 398fa0a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/common/enterprise-util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {dialog} from "electron/main";
import fs from "node:fs";
import path from "node:path";
import process from "node:process";
Expand All @@ -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<
Expand Down Expand Up @@ -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);
}
Expand Down
9 changes: 9 additions & 0 deletions app/common/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
};
}

0 comments on commit 398fa0a

Please sign in to comment.