Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: Improved error handling for invalid JSON in global_config.json #1405

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`,
};
}