{"record":{"id":"1004a8661efc4b41","repo":"usebruno/bruno","slug":"collection-collectionpath-already-exists","errorCode":null,"errorMessage":"collection: ${collectionPath} already exists","messagePattern":"collection: (.+?) already exists","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bruno-electron/src/utils/collection-import.js","lineNumber":34,"sourceCode":"  if (fs.existsSync(collectionPath)) {\n    return findUniqueFolderName(baseName, collectionLocation, counter + 1);\n  }\n\n  return folderName;\n}\n\n/**\n * Import a collection - shared logic used by both IPC handler and onboarding service\n * @param {Object} options - Optional settings\n * @param {boolean} options.skipOpenEvent - If true, don't send main:collection-opened event (caller will handle it)\n */\nasync function importCollection(collection, collectionLocation, mainWindow, uniqueFolderName = null, format = DEFAULT_COLLECTION_FORMAT, options = {}) {\n  // Use provided unique folder name or use collection name\n  let folderName = uniqueFolderName ? sanitizeName(uniqueFolderName) : sanitizeName(collection.name);\n  let collectionPath = path.join(collectionLocation, folderName);\n\n  if (fs.existsSync(collectionPath)) {\n    throw new Error(`collection: ${collectionPath} already exists`);\n  }\n\n  // Recursive function to parse the collection items and create files/folders\n  const parseCollectionItems = async (items = [], currentPath) => {\n    for (const item of items) {\n      if (['http-request', 'graphql-request', 'grpc-request'].includes(item.type)) {\n        let sanitizedFilename = sanitizeName(item.filename || `${item.name}.${format}`);\n        const content = await stringifyRequestViaWorker(item, { format });\n        const filePath = path.join(currentPath, sanitizedFilename);\n        safeWriteFileSync(filePath, content);\n      }\n      if (item.type === 'folder') {\n        let sanitizedFolderName = sanitizeName(item.filename || item.name);\n        const folderPath = path.join(currentPath, sanitizedFolderName);\n        fs.mkdirSync(folderPath);\n\n        if (item.root?.meta?.name) {\n          const folderFilePath = path.join(folderPath, `folder.${format}`);","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-electron/src/utils/collection-import.js#L16-L52","documentation":"Thrown by importCollection at the top of the flow: the computed collectionPath (collectionLocation + sanitized folder name) already exists on disk. This is a preflight check before createDirectory is called, intended to stop an import from clobbering an existing collection.","triggerScenarios":"Importing a collection whose sanitized name collides with an existing folder at collectionLocation; re-importing the same collection twice; user typed a name that sanitizes to an already-present folder.","commonSituations":"Duplicate import attempts; two collections with the same name; sanitizeName collapsing different names to the same slug; leftover folder from a failed prior import.","solutions":["Use findUniqueFolderName(baseName, collectionLocation) to auto-pick a non-colliding name before calling importCollection.","Prompt the user to rename, overwrite, or skip when a collision is detected.","If the folder is a leftover from a failed import, remove it or choose a different location.","Pass an explicit uniqueFolderName argument to importCollection."],"exampleFix":"// before\nlet folderName = uniqueFolderName ? sanitizeName(uniqueFolderName) : sanitizeName(collection.name);\nlet collectionPath = path.join(collectionLocation, folderName);\nif (fs.existsSync(collectionPath)) {\n  throw new Error(`collection: ${collectionPath} already exists`);\n}\n\n// after: de-collide first\nconst folderName = await findUniqueFolderName(\n  uniqueFolderName || collection.name,\n  collectionLocation\n);\nconst collectionPath = path.join(collectionLocation, sanitizeName(folderName));","handlingStrategy":"validation","validationCode":"const folderName = await findUniqueFolderName(uniqueFolderName || collection.name, collectionLocation);\nconst collectionPath = path.join(collectionLocation, sanitizeName(folderName));\nif (fs.existsSync(collectionPath)) {\n  throw new Error(`Refusing to import: ${collectionPath} already exists`);\n}","typeGuard":"function isImportPathClear(collectionLocation, folderName) {\n  return !fs.existsSync(path.join(collectionLocation, sanitizeName(folderName)));\n}","tryCatchPattern":"try {\n  await importCollection(collection, collectionLocation, mainWindow, uniqueFolderName, format, options);\n} catch (err) {\n  if (err.message.includes('already exists')) {\n    const unique = await findUniqueFolderName(collection.name, collectionLocation);\n    return importCollection(collection, collectionLocation, mainWindow, unique, format, options);\n  }\n  throw err;\n}","preventionTips":["Always compute a unique folder name before importing.","Offer overwrite/rename/skip to the user on collision rather than aborting.","Remember sanitizeName can collapse distinct names to the same slug."],"tags":["import","name-collision","filesystem"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}