{"record":{"id":"49c0d93d50272bab","repo":"usebruno/bruno","slug":"a-file-with-the-name-targetfilename-already-e","errorCode":null,"errorMessage":"A file with the name \"${targetFilename}\" already exists in the target location","messagePattern":"A file with the name \"(.+?)\" already exists in the target location","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/bruno-electron/src/ipc/collection.js","lineNumber":1720,"sourceCode":"    try {\n      if (!fs.existsSync(sourcePathname)) {\n        throw new Error(`Source path: ${sourcePathname} does not exist`);\n      }\n      if (!fs.existsSync(targetDirname)) {\n        throw new Error(`Target directory: ${targetDirname} does not exist`);\n      }\n\n      validatePathIsInsideCollection(sourcePathname);\n      validatePathIsInsideCollection(targetDirname);\n\n      const sourceBasename = path.basename(sourcePathname);\n      const filenameWithoutExt = sourceBasename.replace(/\\.(bru|yml|yaml)$/, '');\n      const targetExt = targetFormat === 'yml' ? 'yml' : 'bru';\n      const targetFilename = `${filenameWithoutExt}.${targetExt}`;\n      const targetPathname = path.join(targetDirname, targetFilename);\n\n      if (fs.existsSync(targetPathname)) {\n        throw new Error(`A file with the name \"${targetFilename}\" already exists in the target location`);\n      }\n\n      const sourceContent = await fs.promises.readFile(sourcePathname, 'utf8');\n      const parsedRequest = parseRequest(sourceContent, { format: sourceFormat });\n      const finalContent = stringifyRequest(parsedRequest, { format: targetFormat });\n\n      await writeFile(targetPathname, finalContent);\n      await removePath(sourcePathname);\n\n      moveRequestUid(sourcePathname, targetPathname);\n\n      return { newPathname: targetPathname };\n    } catch (error) {\n      return Promise.reject(error);\n    }\n  });\n\n  ipcMain.handle('renderer:move-folder-item', async (event, folderPath, destinationPath) => {","sourceCodeStart":1702,"sourceCodeEnd":1738,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-electron/src/ipc/collection.js#L1702-L1738","documentation":"Thrown by 'renderer:move-item-cross-format' when fs.existsSync(targetPathname) is true after building targetPathname = targetDirname/<basename>.<targetExt>. The handler will not overwrite an existing request file in the destination.","triggerScenarios":"Moving a request whose base name (minus extension) matches an existing file in the target folder, especially common during cross-format moves where 'req.bru' and 'req.yml' derive the same target filename.","commonSituations":"Same-named request exists in the target format, partial migration left a converted file behind, or duplicate filenames across folders being merged.","solutions":["Pre-check for a colliding target filename and either auto-rename or prompt the user.","If the existing file is a stale migration artifact, remove it before the move.","Use generateUniqueName to derive a non-colliding target filename."],"exampleFix":"// before\nawait window.Ipc.invoke('renderer:move-item-cross-format', { targetDirname, sourcePathname, sourceFormat, targetFormat });\n\n// after\n// compute target up front and rename on collision (caller-side) or extend handler to accept a force/overwrite flag\nconst targetExt = targetFormat === 'yml' ? 'yml' : 'bru';\nlet targetPathname = path.join(targetDirname, `${base}.${targetExt}`);\nif (fs.existsSync(targetPathname)) targetPathname = path.join(targetDirname, `${base}-copy.${targetExt}`);\n// pass explicit target via an extended payload if supported, or pre-resolve by renaming source first","handlingStrategy":"validation","validationCode":"const targetExt = targetFormat === 'yml' ? 'yml' : 'bru';\nconst base = sourcePathname.replace(/\\.(bru|yml|yaml)$/, '');\nconst targetPathname = path.join(targetDirname, `${path.basename(base)}.${targetExt}`);\nif (await window.ipc.invoke('main:path-exists', targetPathname)) {\n  throw new Error(`a ${targetExt} file with that name already exists in the target`);\n}","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:move-item-cross-format', payload);\n} catch (e) {\n  if (String(e?.message).includes('already exists in the target')) {\n    // rename source first or pick a different target filename and retry\n    await suggestAlternateNameAndRetry(payload);\n  } else throw e;\n}","preventionTips":["Pre-check the derived target filename for collisions.","Use generateUniqueName when collisions are likely during migration.","Prompt the user on cross-format name clashes."],"tags":["ipc","move","cross-format","conflict","filesystem"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}