{"record":{"id":"6a367196b11fbc67","repo":"usebruno/bruno","slug":"path-newpath-already-exists","errorCode":null,"errorMessage":"path: ${newPath} already exists","messagePattern":"path: (.+?) already exists","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/bruno-electron/src/ipc/collection.js","lineNumber":1104,"sourceCode":"      return Promise.reject(error);\n    }\n  });\n\n  // rename item\n  ipcMain.handle('renderer:rename-item-filename', async (event, { oldPath, newPath, newName, newFilename, collectionPathname }) => {\n    const tempDir = path.join(os.tmpdir(), `temp-folder-${Date.now()}`);\n    const isWindowsOSAndNotWSLPathAndItemHasSubDirectories = isDirectory(oldPath) && isWindowsOS() && !isWSLPath(oldPath) && hasSubDirectories(oldPath);\n    try {\n      validatePathIsInsideCollection(oldPath);\n      validatePathIsInsideCollection(newPath);\n\n      // Check if the old path exists\n      if (!fs.existsSync(oldPath)) {\n        throw new Error(`path: ${oldPath} does not exist`);\n      }\n\n      if (!safeToRename(oldPath, newPath)) {\n        throw new Error(`path: ${newPath} already exists`);\n      }\n\n      const format = getCollectionFormat(collectionPathname);\n\n      if (isDirectory(oldPath)) {\n        const folderFilePath = path.join(oldPath, `folder.${format}`);\n        let folderFileJsonContent;\n        if (fs.existsSync(folderFilePath)) {\n          const oldFolderFileContent = await fs.promises.readFile(folderFilePath, 'utf8');\n          folderFileJsonContent = await parseFolder(oldFolderFileContent, { format });\n          folderFileJsonContent.meta.name = newName;\n        } else {\n          folderFileJsonContent = {\n            meta: {\n              name: newName\n            }\n          };\n        }","sourceCodeStart":1086,"sourceCodeEnd":1122,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-electron/src/ipc/collection.js#L1086-L1122","documentation":"Thrown by 'renderer:rename-item-filename' when safeToRename(oldPath, newPath) returns false — i.e. newPath already exists and is not the same inode/birthtime as oldPath. The handler refuses to clobber an existing distinct file/folder.","triggerScenarios":"Choosing a new filename that collides with an existing item in the same folder, case-only rename on case-insensitive filesystems where both forms exist, or renaming to a name a sibling already holds.","commonSituations":"User typed a name already used by another request/folder, or two items differ only by case on macOS/Windows.","solutions":["Pre-check for name collisions in the destination folder and auto-suggest a unique name (Bruno's generateUniqueName pattern).","On case-insensitive FS, treat case-only renames specially or warn the user.","Surface the existing-target conflict to the user with a 'replace / rename / cancel' choice."],"exampleFix":"// before\nawait window.Ipc.invoke('renderer:rename-item-filename', { oldPath, newPath: path.join(dir, takenName), newName, newFilename, collectionPathname });\n\n// after\nconst dir = path.dirname(oldPath);\nlet candidate = newFilename;\nwhile (fs.existsSync(path.join(dir, candidate))) candidate = `${newFilename}-copy`;\nawait window.Ipc.invoke('renderer:rename-item-filename', { oldPath, newPath: path.join(dir, candidate), newName, newFilename: candidate, collectionPathname });","handlingStrategy":"validation","validationCode":"const dir = path.dirname(oldPath);\nif (fs.existsSyncSync?.(newPath) || (await window.ipc.invoke('main:path-exists', newPath))) {\n  throw new Error(`'${path.basename(newPath)}' already exists in this folder`);\n}","typeGuard":"function isNewPathSafe(safe: boolean): boolean { return safe; } // safeToRename result mirror\n\nasync 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:rename-item-filename', payload);\n} catch (e) {\n  if (String(e?.message).includes('already exists')) {\n    payload.newFilename = await suggestUniqueName(payload.newFilename);\n    await window.Ipc.invoke('renderer:rename-item-filename', payload);\n  } else throw e;\n}","preventionTips":["Suggest a unique name when the destination already has it.","Warn about case-only collisions on case-insensitive filesystems.","List sibling names in the rename dialog."],"tags":["ipc","rename","conflict","filesystem","validation"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}