SDA-4265 (Handle uncaught exceptions) (#1933)

* SDA-4265 - Handle uncaught exception

Signed-off-by: Kiran Niranjan <kiran.niranjan@symphony.com>

* SDA-4265 - Add safety check for user config

Signed-off-by: Kiran Niranjan <kiran.niranjan@symphony.com>

* SDA-4265 - Add safety check for user config

Signed-off-by: Kiran Niranjan <kiran.niranjan@symphony.com>

---------

Signed-off-by: Kiran Niranjan <kiran.niranjan@symphony.com>
This commit is contained in:
Kiran Niranjan 2023-08-14 10:10:58 +05:30 committed by GitHub
parent 59d02c7dd6
commit 729a828c5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 0 deletions

View File

@ -248,6 +248,10 @@ class Config {
* @param fields {Array}
*/
public getUserConfigFields(fields: string[]): IConfig {
if (!this.userConfig) {
logger.error(`config-handler: user config is undefined`, this.userConfig);
return {} as IConfig;
}
const userConfigData = pick(this.userConfig, fields) as IConfig;
logger.info(
`config-handler: getting user config values for the fields ${fields}`,
@ -328,6 +332,9 @@ class Config {
* Writes the config data into the user config file
*/
public writeUserConfig = async (): Promise<void> => {
if (!this.userConfig) {
return;
}
logger.info(`config-handler: Updating user config file`);
try {
await writeFile(
@ -571,6 +578,13 @@ class Config {
public async readUserConfig() {
if (fs.existsSync(this.userConfigPath)) {
const userConfig = fs.readFileSync(this.userConfigPath, 'utf8');
if (!userConfig) {
logger.error(
`config-handler: User configuration is empty and nothing to read`,
userConfig,
);
return;
}
this.userConfig = this.parseConfigData(userConfig);
}
logger.info(`config-handler: User configuration: `, this.userConfig);

View File

@ -9,6 +9,7 @@ import {
dialog,
Event,
ipcMain,
MessageBoxSyncOptions,
nativeTheme,
RenderProcessGoneDetails,
screen,
@ -210,6 +211,25 @@ export class WindowHandler {
);
}
this.listenForLoad();
// Handle uncaught exception and terminate application
process.on('uncaughtException', async (error) => {
logger.error('window-handler: uncaught exception', error);
const messageBoxOptions: MessageBoxSyncOptions = {
type: 'question',
title: i18n.t('Relaunch Application')(),
message: i18n.t(
`Error in Main Process. Would you like to restart the app?`,
)(),
detail: error.message,
buttons: [i18n.t('Relaunch')(), i18n.t('Cancel')()],
cancelId: 1,
};
const response = dialog.showMessageBoxSync(messageBoxOptions);
if (response === 0) {
await windowHandler.exitApplication(true);
}
});
}
/**

View File

@ -72,6 +72,7 @@
"Edit": "Edit",
"Enable Hamburger menu": "Enable Hamburger menu",
"Enable GPU": "Enable GPU",
"Error in Main Process. Would you like to restart the app?": "Error in Main Process. Would you like to restart the app?",
"Error loading configuration": "Error loading configuration",
"Error loading URL": "Error loading URL",
"Error loading window": "Error loading window",

View File

@ -72,6 +72,7 @@
"Edit": "Edit",
"Enable Hamburger menu": "Enable Hamburger menu",
"Enable GPU": "Enable GPU",
"Error in Main Process. Would you like to restart the app?": "Error in Main Process. Would you like to restart the app?",
"Error loading configuration": "Error loading configuration",
"Error loading URL": "Error loading URL",
"Error loading window": "Error loading window",