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,6 +67,7 @@ export default function ExportModal(props: Props) {
// SIDE EFFECTS // SIDE EFFECTS
// ==================== // ====================
useEffect(() => { useEffect(() => {
try {
if (!isElectron()) { if (!isElectron()) {
return; return;
} }
@ -74,10 +75,15 @@ export default function ExportModal(props: Props) {
exportService.electronAPIs.registerStopExportListener(stopExport); exportService.electronAPIs.registerStopExportListener(stopExport);
exportService.electronAPIs.registerPauseExportListener(pauseExport); exportService.electronAPIs.registerPauseExportListener(pauseExport);
exportService.electronAPIs.registerResumeExportListener(resumeExport); exportService.electronAPIs.registerResumeExportListener(
resumeExport
);
exportService.electronAPIs.registerRetryFailedExportListener( exportService.electronAPIs.registerRetryFailedExportListener(
retryFailedExport retryFailedExport
); );
} catch (e) {
logError(e, 'error while registering export listeners');
}
}, []); }, []);
useEffect(() => { useEffect(() => {
@ -85,10 +91,13 @@ export default function ExportModal(props: Props) {
return; return;
} }
const main = async () => { const main = async () => {
try {
const exportInfo = await exportService.getExportRecord(); const exportInfo = await exportService.getExportRecord();
setExportStage(exportInfo?.stage ?? ExportStage.INIT); setExportStage(exportInfo?.stage ?? ExportStage.INIT);
setLastExportTime(exportInfo?.lastAttemptTimestamp); setLastExportTime(exportInfo?.lastAttemptTimestamp);
setExportProgress(exportInfo?.progress ?? { current: 0, total: 0 }); setExportProgress(
exportInfo?.progress ?? { current: 0, total: 0 }
);
setExportStats({ setExportStats({
success: exportInfo?.exportedFiles?.length ?? 0, success: exportInfo?.exportedFiles?.length ?? 0,
failed: exportInfo?.failedFiles?.length ?? 0, failed: exportInfo?.failedFiles?.length ?? 0,
@ -96,6 +105,12 @@ export default function ExportModal(props: Props) {
if (exportInfo?.stage === ExportStage.INPROGRESS) { if (exportInfo?.stage === ExportStage.INPROGRESS) {
resumeExport(); resumeExport();
} }
} catch (e) {
logError(
e,
'error while updating exportModal on exportFolder change'
);
}
}; };
main(); main();
}, [exportFolder]); }, [exportFolder]);
@ -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 () => {
try {
const newFolder = await exportService.selectExportDirectory(); const newFolder = await exportService.selectExportDirectory();
if (newFolder) { if (newFolder) {
updateExportFolder(newFolder); updateExportFolder(newFolder);
} else { }
throw Error(CustomError.REQUEST_CANCELLED); } catch (e) {
logError(e, 'selectExportDirectory failed');
} }
}; };