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

View File

@ -9,6 +9,7 @@ import {
dialog, dialog,
Event, Event,
ipcMain, ipcMain,
MessageBoxSyncOptions,
nativeTheme, nativeTheme,
RenderProcessGoneDetails, RenderProcessGoneDetails,
screen, screen,
@ -210,6 +211,25 @@ export class WindowHandler {
); );
} }
this.listenForLoad(); 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", "Edit": "Edit",
"Enable Hamburger menu": "Enable Hamburger menu", "Enable Hamburger menu": "Enable Hamburger menu",
"Enable GPU": "Enable GPU", "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 configuration": "Error loading configuration",
"Error loading URL": "Error loading URL", "Error loading URL": "Error loading URL",
"Error loading window": "Error loading window", "Error loading window": "Error loading window",

View File

@ -72,6 +72,7 @@
"Edit": "Edit", "Edit": "Edit",
"Enable Hamburger menu": "Enable Hamburger menu", "Enable Hamburger menu": "Enable Hamburger menu",
"Enable GPU": "Enable GPU", "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 configuration": "Error loading configuration",
"Error loading URL": "Error loading URL", "Error loading URL": "Error loading URL",
"Error loading window": "Error loading window", "Error loading window": "Error loading window",