From c30b4ff3c60b7cb631a5217297b531c1cc069f84 Mon Sep 17 00:00:00 2001 From: Robert Hailey Date: Mon, 2 Dec 2024 09:50:01 -0600 Subject: [PATCH] Prevent data-loss if we are unable to write the new file --- packages/bruno-electron/src/ipc/collection.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index 38261cdb..bbf25445 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -392,8 +392,9 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection moveRequestUid(oldPath, newPath); const content = jsonToBru(jsonData); - await fs.promises.unlink(oldPath); + // we must write the new file first to avoid data loss if an exception occurs during write await writeFile(newPath, content); + await fs.promises.unlink(oldPath); return newPath; } catch (error) {