{"record":{"id":"1d9ce9872d507854","repo":"usebruno/bruno","slug":"folder-collectionpath-already-exists","errorCode":null,"errorMessage":"folder: ${collectionPath} already exists","messagePattern":"folder: (.+?) already exists","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/bruno-electron/src/ipc/collection.js","lineNumber":1549,"sourceCode":"          failed: failedImports\n        }\n      });\n    }\n\n    return {\n      success: {\n        count: completedImports,\n        items: successfulImports\n      }\n    };\n  });\n\n  ipcMain.handle('renderer:clone-folder', async (event, itemFolder, collectionPath, collectionPathname) => {\n    try {\n      validatePathIsInsideCollection(collectionPath);\n\n      if (fs.existsSync(collectionPath)) {\n        throw new Error(`folder: ${collectionPath} already exists`);\n      }\n\n      const format = getCollectionFormat(collectionPathname);\n\n      // Recursive function to parse the folder and create files/folders\n      const parseCollectionItems = (items = [], currentPath) => {\n        items.forEach(async (item) => {\n          if (['http-request', 'graphql-request', 'grpc-request'].includes(item.type)) {\n            const content = await stringifyRequestViaWorker(item, { format });\n\n            // Use the correct file extension based on target format\n            const baseName = path.parse(item.filename).name;\n            const newFilename = format === 'yml' ? `${baseName}.yml` : `${baseName}.bru`;\n            const filePath = path.join(currentPath, newFilename);\n\n            safeWriteFileSync(filePath, content);\n          }\n          if (item.type === 'folder') {","sourceCodeStart":1531,"sourceCodeEnd":1567,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-electron/src/ipc/collection.js#L1531-L1567","documentation":"Thrown by 'renderer:clone-folder' when fs.existsSync(collectionPath) is true. The clone handler creates a new folder at collectionPath and refuses to overwrite an existing one.","triggerScenarios":"Cloning a folder into a destination where a folder of the same name already exists, or re-running a clone after a partial/interrupted earlier attempt that left the directory behind.","commonSituations":"Duplicate clone action, target name not uniquified, or a previous failed clone left a partial directory on disk.","solutions":["Generate a unique target name (e.g. 'folder-copy', 'folder-copy-2') before invoking clone.","If the existing folder is a leftover from a failed clone, remove it or let the user choose a different destination.","Surface the conflict and prompt for overwrite/rename/cancel."],"exampleFix":"// before\nawait window.Ipc.invoke('renderer:clone-folder', itemFolder, targetPath, collectionPathname);\n\n// after\nlet target = targetPath; let i = 1;\nwhile (fs.existsSync(target)) target = `${targetPath}-copy-${i++}`;\nawait window.Ipc.invoke('renderer:clone-folder', itemFolder, target, collectionPathname);","handlingStrategy":"validation","validationCode":"let target = collectionPath; let i = 1;\nwhile (await window.ipc.invoke('main:path-exists', target)) target = `${collectionPath}-copy-${i++}`;\nawait window.Ipc.invoke('renderer:clone-folder', itemFolder, target, collectionPathname);","typeGuard":"async function targetIsClear(p: string): Promise<boolean> {\n  return !(await window.ipc.invoke('main:path-exists', p));\n}","tryCatchPattern":"try {\n  await window.Ipc.invoke('renderer:clone-folder', itemFolder, collectionPath, collectionPathname);\n} catch (e) {\n  if (String(e?.message).includes('already exists')) {\n    const uniq = `${collectionPath}-copy-${Date.now()}`;\n    await window.Ipc.invoke('renderer:clone-folder', itemFolder, uniq, collectionPathname);\n  } else throw e;\n}","preventionTips":["Pre-uniquify the target folder name.","Prompt overwrite/rename on collision.","Clean up partial folders from failed clones before retrying."],"tags":["ipc","clone","conflict","filesystem","validation"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}