diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index 0421060dd..30a891015 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -65,14 +65,20 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection try { const dirPath = path.join(collectionLocation, collectionFolderName); if (fs.existsSync(dirPath)) { - throw new Error(`collection: ${dirPath} already exists`); + const files = fs.readdirSync(dirPath); + + if (files.length > 0) { + throw new Error(`collection: ${dirPath} already exists and is not empty`); + } } if (!isValidPathname(dirPath)) { throw new Error(`collection: invalid pathname - ${dir}`); } - await createDirectory(dirPath); + if (!fs.existsSync(dirPath)) { + await createDirectory(dirPath); + } const uid = generateUidBasedOnHash(dirPath); const brunoConfig = {