add missing try catch wrappers

This commit is contained in:
Abhinav 2023-02-21 16:40:44 +05:30
parent e65c0581fb
commit 58f886015a

View file

@ -67,17 +67,23 @@ export default function ExportModal(props: Props) {
// SIDE EFFECTS // SIDE EFFECTS
// ==================== // ====================
useEffect(() => { useEffect(() => {
if (!isElectron()) { try {
return; if (!isElectron()) {
} return;
setExportFolder(getData(LS_KEYS.EXPORT)?.folder); }
setExportFolder(getData(LS_KEYS.EXPORT)?.folder);
exportService.electronAPIs.registerStopExportListener(stopExport); exportService.electronAPIs.registerStopExportListener(stopExport);
exportService.electronAPIs.registerPauseExportListener(pauseExport); exportService.electronAPIs.registerPauseExportListener(pauseExport);
exportService.electronAPIs.registerResumeExportListener(resumeExport); exportService.electronAPIs.registerResumeExportListener(
exportService.electronAPIs.registerRetryFailedExportListener( resumeExport
retryFailedExport );
); exportService.electronAPIs.registerRetryFailedExportListener(
retryFailedExport
);
} catch (e) {
logError(e, 'error while registering export listeners');
}
}, []); }, []);
useEffect(() => { useEffect(() => {
@ -85,16 +91,25 @@ export default function ExportModal(props: Props) {
return; return;
} }
const main = async () => { const main = async () => {
const exportInfo = await exportService.getExportRecord(); try {
setExportStage(exportInfo?.stage ?? ExportStage.INIT); const exportInfo = await exportService.getExportRecord();
setLastExportTime(exportInfo?.lastAttemptTimestamp); setExportStage(exportInfo?.stage ?? ExportStage.INIT);
setExportProgress(exportInfo?.progress ?? { current: 0, total: 0 }); setLastExportTime(exportInfo?.lastAttemptTimestamp);
setExportStats({ setExportProgress(
success: exportInfo?.exportedFiles?.length ?? 0, exportInfo?.progress ?? { current: 0, total: 0 }
failed: exportInfo?.failedFiles?.length ?? 0, );
}); setExportStats({
if (exportInfo?.stage === ExportStage.INPROGRESS) { success: exportInfo?.exportedFiles?.length ?? 0,
resumeExport(); failed: exportInfo?.failedFiles?.length ?? 0,
});
if (exportInfo?.stage === ExportStage.INPROGRESS) {
resumeExport();
}
} catch (e) {
logError(
e,
'error while updating exportModal on exportFolder change'
);
} }
}; };
main(); main();
@ -185,6 +200,7 @@ export default function ExportModal(props: Props) {
updateExportStage(ExportStage.INPROGRESS); updateExportStage(ExportStage.INPROGRESS);
await sleep(100); await sleep(100);
}; };
const postExportRun = async (exportResult?: { paused?: boolean }) => { const postExportRun = async (exportResult?: { paused?: boolean }) => {
if (!exportResult?.paused) { if (!exportResult?.paused) {
updateExportStage(ExportStage.FINISHED); updateExportStage(ExportStage.FINISHED);
@ -195,11 +211,13 @@ export default function ExportModal(props: Props) {
}; };
const selectExportDirectory = async () => { const selectExportDirectory = async () => {
const newFolder = await exportService.selectExportDirectory(); try {
if (newFolder) { const newFolder = await exportService.selectExportDirectory();
updateExportFolder(newFolder); if (newFolder) {
} else { updateExportFolder(newFolder);
throw Error(CustomError.REQUEST_CANCELLED); }
} catch (e) {
logError(e, 'selectExportDirectory failed');
} }
}; };