From b015d2e5367df696d2f4dad555ca871f94afa4cc Mon Sep 17 00:00:00 2001 From: David Langley Date: Fri, 11 Oct 2024 13:48:38 +0100 Subject: [PATCH 1/2] Add try catch for each unlink --- src/seshat.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/seshat.ts b/src/seshat.ts index 63fb6dc..fcdd1d7 100644 --- a/src/seshat.ts +++ b/src/seshat.ts @@ -62,7 +62,9 @@ async function getOrCreatePassphrase(key: string): Promise { const deleteContents = async (p: string): Promise => { for (const entry of await afs.readdir(p)) { const curPath = path.join(p, entry); - await afs.unlink(curPath); + try { + await afs.unlink(curPath); + } catch (e) {} } }; From 64a1d986f945be24e41694a78b89091b8ab0c219 Mon Sep 17 00:00:00 2001 From: David Langley Date: Fri, 11 Oct 2024 17:24:30 +0100 Subject: [PATCH 2/2] Log errors --- src/seshat.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/seshat.ts b/src/seshat.ts index fcdd1d7..2f3183e 100644 --- a/src/seshat.ts +++ b/src/seshat.ts @@ -60,11 +60,17 @@ async function getOrCreatePassphrase(key: string): Promise { } const deleteContents = async (p: string): Promise => { - for (const entry of await afs.readdir(p)) { - const curPath = path.join(p, entry); - try { - await afs.unlink(curPath); - } catch (e) {} + try { + for (const entry of await afs.readdir(p)) { + const curPath = path.join(p, entry); + try { + await afs.unlink(curPath); + } catch (e) { + console.log("Error deleting a file in EventStore directory", e); + } + } + } catch (e) { + console.log("Error reading the files in EventStore directory", e); } }; @@ -117,10 +123,7 @@ ipcMain.on("seshat", async function (_ev: IpcMainEvent, payload): Promise // anyways so reindexing it is a waste of time. if (userVersion === 0) { await recoveryIndex.shutdown(); - - try { - await deleteContents(eventStorePath); - } catch (e) {} + await deleteContents(eventStorePath); } else { await recoveryIndex.reindex(); } @@ -149,9 +152,7 @@ ipcMain.on("seshat", async function (_ev: IpcMainEvent, payload): Promise break; case "deleteEventIndex": { - try { - await deleteContents(eventStorePath); - } catch (e) {} + await deleteContents(eventStorePath); break; }