{"record":{"id":"22cca657c4f1982d","repo":"usebruno/bruno","slug":"a-file-with-the-name-finalfilename-already-ex","errorCode":null,"errorMessage":"A file with the name \"${finalFilename}\" already exists in the target location","messagePattern":"A file with the name \"(.+?)\" already exists in the target location","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/bruno-electron/src/ipc/collection.js","lineNumber":608,"sourceCode":"      if (!fs.existsSync(targetDirname)) {\n        throw new Error(`Target directory: ${targetDirname} does not exist`);\n      }\n\n      validatePathIsInsideCollection(targetDirname);\n\n      const collectionPath = findCollectionPathByItemPath(targetDirname);\n      if (!collectionPath) {\n        throw new Error('Could not determine collection for target directory');\n      }\n      const targetFormat = getCollectionFormat(collectionPath);\n\n      const filename = targetFilename || path.basename(sourcePathname);\n      const filenameWithoutExt = filename.replace(/\\.(bru|yml)$/, '');\n      const finalFilename = `${filenameWithoutExt}.${targetFormat}`;\n      const targetPathname = path.join(targetDirname, finalFilename);\n\n      if (fs.existsSync(targetPathname)) {\n        throw new Error(`A file with the name \"${finalFilename}\" already exists in the target location`);\n      }\n\n      const actualSourceFormat = sourceFormat || 'yml';\n      const needsConversion = actualSourceFormat !== targetFormat;\n\n      let finalContent;\n      if (needsConversion) {\n        const { parseRequest, stringifyRequest } = require('@usebruno/filestore');\n        const sourceContent = await fs.promises.readFile(sourcePathname, 'utf8');\n        const parsedRequest = parseRequest(sourceContent, { format: actualSourceFormat });\n        const mergedRequest = { ...parsedRequest, ...request };\n        syncExampleUidsCache(sourcePathname, mergedRequest.examples);\n        finalContent = stringifyRequest(mergedRequest, { format: targetFormat });\n      } else {\n        syncExampleUidsCache(sourcePathname, request.examples);\n        finalContent = await stringifyRequestViaWorker(request, { format: targetFormat });\n      }\n","sourceCodeStart":590,"sourceCodeEnd":626,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-electron/src/ipc/collection.js#L590-L626","documentation":"Thrown by 'renderer:save-transient-request' when fs.existsSync(targetPathname) is true — i.e. a file with the computed finalFilename already exists in targetDirname. The handler computes finalFilename as `<basename without .bru/.yml>.<targetFormat>` and refuses to clobber an existing request file.","triggerScenarios":"Moving/saving a transient request whose name collides with an existing request in the target folder. Two transient requests with the same name saved to the same folder. Case-insensitive filesystems (Windows/macOS) where 'Foo.bru' collides with 'foo.bru'.","commonSituations":"Duplicate request names across folders merged into one. Repeated save of a transient tab after one already landed. Case-fold collisions on macOS/Windows.","solutions":["Generate a unique target filename (append ' (1)', ' (2)', etc.) before saving.","Prompt the user to overwrite, rename, or skip; only overwrite via an explicit delete of the target first.","Check fs.existsSync(targetPathname) in the UI before opening the save dialog."],"exampleFix":"// before\nawait window.ipcRenderer.invoke('renderer:save-transient-request', { ..., targetFilename });\n\n// after\nlet candidate = targetFilename;\nlet i = 1;\nwhile (await window.ipcRenderer.invoke('renderer:file-exists', path.join(targetDirname, candidate))) {\n  candidate = `${base} (${i++}).${format}`;\n}\nawait window.ipcRenderer.invoke('renderer:save-transient-request', { ..., targetFilename: candidate });","handlingStrategy":"validation","validationCode":"const candidate = path.join(targetDirname, finalFilename);\nif (await window.ipcRenderer.invoke('renderer:file-exists', candidate)) {\n  // prompt overwrite or generate a unique name\n}","typeGuard":null,"tryCatchPattern":"try {\n  await window.ipcRenderer.invoke('renderer:save-transient-request', payload);\n} catch (e) {\n  if (/already exists in the target location/.test(e.message)) {\n    payload.targetFilename = makeUnique(payload.targetFilename);\n    await window.ipcRenderer.invoke('renderer:save-transient-request', payload);\n  } else throw e;\n}","preventionTips":["Check the target name against the destination folder listing before saving.","Generate unique names on collision rather than failing.","Remember case-insensitive collisions on Windows/macOS when picking a name."],"tags":["ipc","filesystem","request","validation","bruno"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}