{"record":{"id":"46bfc7d4b52b8976","repo":"usebruno/bruno","slug":"filename-file-already-exists","errorCode":null,"errorMessage":"${filename} file already exists","messagePattern":"(.+?) file already exists","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/bruno-electron/src/ipc/collection.js","lineNumber":904,"sourceCode":"    } catch (error) {\n      console.error('Error saving .env file:', error);\n      return Promise.reject(error);\n    }\n  });\n\n  // Create .env file for collection\n  ipcMain.handle('renderer:create-dotenv-file', async (event, collectionPathname, filename = '.env') => {\n    try {\n      if (!isValidDotEnvFilename(filename)) {\n        throw new Error('Invalid .env filename');\n      }\n\n      validatePathIsInsideCollection(collectionPathname);\n\n      const dotEnvPath = path.join(collectionPathname, filename);\n\n      if (fs.existsSync(dotEnvPath)) {\n        throw new Error(`${filename} file already exists`);\n      }\n\n      await writeFile(dotEnvPath, '');\n\n      return { success: true, filename };\n    } catch (error) {\n      console.error('Error creating .env file:', error);\n      return Promise.reject(error);\n    }\n  });\n\n  // Delete .env file for collection\n  ipcMain.handle('renderer:delete-dotenv-file', async (event, collectionPathname, filename = '.env') => {\n    try {\n      if (!isValidDotEnvFilename(filename)) {\n        throw new Error('Invalid .env filename');\n      }\n","sourceCodeStart":886,"sourceCodeEnd":922,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-electron/src/ipc/collection.js#L886-L922","documentation":"Thrown by 'renderer:create-dotenv-file' when fs.existsSync(dotEnvPath) is true — the dotenv file already exists, and create refuses to overwrite. dotEnvPath is path.join(collectionPathname, filename). The filename was already validated (error 197) and the path confirmed to be inside a collection.","triggerScenarios":"Creating a dotenv file whose name already exists in the collection root. Repeated create after a previous create succeeded. Case-fold collision on Windows/macOS.","commonSituations":"User clicks 'Create .env' twice. Bulk import that creates the file then the UI retries. Case-insensitive collision between '.env.Local' and '.env.local'.","solutions":["Check existence before creating; if the file exists, open/edit it instead of creating.","Prompt the user to overwrite (delete then create) or pick a different name.","Treat 'already exists' as a non-error and route the user to editing the existing file."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const candidate = path.join(collectionPathname, filename);\nif (await window.ipcRenderer.invoke('renderer:file-exists', candidate)) {\n  // already exists — route to edit instead of create\n}","typeGuard":null,"tryCatchPattern":"try {\n  await window.ipcRenderer.invoke('renderer:create-dotenv-file', collectionPath, filename);\n} catch (e) {\n  if (/file already exists/.test(e.message)) {\n    await openDotEnvEditor(collectionPath, filename);\n  } else throw e;\n}","preventionTips":["Check existence before creating; switch to edit mode if the file is present.","Treat 'already exists' as a soft state, not an error, in the UI.","Watch for case-insensitive collisions on Windows/macOS."],"tags":["ipc","filesystem","dotenv","validation","bruno"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}